Modeler FlowでJSONファイルを読む

CP4DのModelerFlowでICOS上にあるJSONファイルを読んでみます。

* テスト環境
CP4D 4.0.9

# 1. JSONデータの読み込み

データ資産のノードを配置し、編集します。
![image.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/223763/fc29206b-ec97-b6f9-eb70-8940e29d95ac.png)


ファイルを選びます。
![image.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/223763/fba2ee2f-14e0-af26-38b8-fa93cf15abf4.png)

ここでは行タイプのJSONを選んでいます。

```json:Cond4n_e10r.json
[{"M_CD":1000,"UP_TIME":0,"POWER":948,"TEMP":250,"ERR_CD":0},
{"M_CD":1000,"UP_TIME":1,"POWER":945,"TEMP":250,"ERR_CD":0},
{"M_CD":1000,"UP_TIME":2,"POWER":944,"TEMP":250,"ERR_CD":0},
{"M_CD":1000,"UP_TIME":3,"POWER":943,"TEMP":250,"ERR_CD":0},
{"M_CD":1000,"UP_TIME":4,"POWER":940,"TEMP":250,"ERR_CD":0},
{"M_CD":1000,"UP_TIME":5,"POWER":938,"TEMP":250,"ERR_CD":0},
{"M_CD":1000,"UP_TIME":6,"POWER":936,"TEMP":250,"ERR_CD":0},
{"M_CD":1000,"UP_TIME":7,"POWER":936,"TEMP":250,"ERR_CD":0},
{"M_CD":1000,"UP_TIME":8,"POWER":935,"TEMP":251,"ERR_CD":0}]
```

保存します。
![image.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/223763/89f44dbe-0531-3591-dfbf-cbebcbfd9b40.png)

プレビューをすると正しく読めていることがわかります。

![image.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/223763/bcab1b39-b48c-601a-705e-a5b5afda2ed0.png)

# 2. 様々なJSONのパターンを読む

圧縮されていたjson.gzはそのまま読めました。
![image.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/223763/d01946ef-a97f-845c-0401-cb62fd186b11.png)


![image.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/223763/066f1276-6a1d-47fc-f7cc-04002748c2f7.png)

テーブルタイプのJSONはJSONパス（$.data）を指定する必要がありました。

```json:Cond4n_e10t.json
{"schema":{"fields":[{"name":"index","type":"integer"},{"name":"M_CD","type":"integer"},
{"name":"UP_TIME","type":"integer"},{"name":"POWER","type":"integer"},{"name":"TEMP","type":"integer"},
{"name":"ERR_CD","type":"integer"}],"primaryKey":["index"],"pandas_version":"1.4.0"},"data":
[{"index":0,"M_CD":1000,"UP_TIME":0,"POWER":948,"TEMP":250,"ERR_CD":0},
{"index":1,"M_CD":1000,"UP_TIME":1,"POWER":945,"TEMP":250,"ERR_CD":0},
{"index":2,"M_CD":1000,"UP_TIME":2,"POWER":944,"TEMP":250,"ERR_CD":0},
{"index":3,"M_CD":1000,"UP_TIME":3,"POWER":943,"TEMP":250,"ERR_CD":0},
{"index":4,"M_CD":1000,"UP_TIME":4,"POWER":940,"TEMP":250,"ERR_CD":0},
{"index":5,"M_CD":1000,"UP_TIME":5,"POWER":938,"TEMP":250,"ERR_CD":0},
{"index":6,"M_CD":1000,"UP_TIME":6,"POWER":936,"TEMP":250,"ERR_CD":0},
{"index":7,"M_CD":1000,"UP_TIME":7,"POWER":936,"TEMP":250,"ERR_CD":0},
{"index":8,"M_CD":1000,"UP_TIME":8,"POWER":935,"TEMP":251,"ERR_CD":0}]}
```
![image.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/223763/c16c4570-cb3b-8fbd-7831-dc03dfce5dce.png)

![image.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/223763/0a5b00d0-d6ca-244c-21fd-66ed8ada3cc2.png)

# 3. 読めないパターンのJSON

カラム型のJSONは一行で読まれてしまいます。

```json:Cond4n_e10c.json
{"M_CD":{"0":1000,"1":1000,"2":1000,"3":1000,"4":1000,"5":1000,"6":1000,"7":1000,"8":1000},
"UP_TIME":{"0":0,"1":1,"2":2,"3":3,"4":4,"5":5,"6":6,"7":7,"8":8},
"POWER":{"0":948,"1":945,"2":944,"3":943,"4":940,"5":938,"6":936,"7":936,"8":935},
"TEMP":{"0":250,"1":250,"2":250,"3":250,"4":250,"5":250,"6":250,"7":250,"8":251},
"ERR_CD":{"0":0,"1":0,"2":0,"3":0,"4":0,"5":0,"6":0,"7":0,"8":0}}
```



![image.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/223763/4896f43e-b3a4-92cf-bef3-22679eb5b159.png)

Schema型のJSONはdataの列にまとめて入ってしまいます。
```json:Cond4n_e10s.json
{"columns":["M_CD","UP_TIME","POWER","TEMP","ERR_CD"],"index":[0,1,2,3,4,5,6,7,8],
"data":[[1000,0,948,250,0],[1000,1,945,250,0],[1000,2,944,250,0],[1000,3,943,250,0],[1000,4,940,250,0],[1000,5,938,250,0],[1000,6,936,250,0],[1000,7,936,250,0],[1000,8,935,251,0]]}
```
![image.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/223763/2a2a119d-9225-6916-4af4-9bf67347f6b2.png)


Value型のJSONは読めませんでした。
```json:Cond4n_e10v.json
[[1000,0,948,250,0],[1000,1,945,250,0],[1000,2,944,250,0],[1000,3,943,250,0],[1000,4,940,250,0],[1000,5,938,250,0],[1000,6,936,250,0],[1000,7,936,250,0],[1000,8,935,251,0]]
```

![image.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/223763/345eaaca-3505-654c-95f2-b63d74a672f3.png)