Flux - Experimental json.parse()


I’m experimenting with the json.parse function but I’m blocked. From the help:

The json.parse() function takes JSON data as bytes and returns a value. The function can return lists, records, strings, booleans, and float values.

The example is quite simple and its lacking details on the “lists, records” part I’m interested in.

I would like to test a more complexe scenario:
I’m loading a json file (from couchdb). I’m doing it using the experimental http.get function.
I would like to parse it into a stream of tables
Then I will for exemple join it with data I have in influxDB

my json look likes:
“_id”: “masterSamples”,
“_rev”: “3-0d9d8777759e681c780688a6051a41e9”,
“masterSamples”: [
“ProductCode”: “PS000607”,
“FaultCode”: 8530,
“FaultDesc”: “default 8530”
“ProductCode”: “PS000807”,
“FaultCode”: 7330,
“FaultDesc”: “default 7330”
“ProductCode”: “PS000307”,
“FaultCode”: 7130,
“FaultDesc”: “default 7130”

I would like to parse it into a table having a column ProductCode, FaultCode, FaultDesc.

Is it achievable in flux ?



It looks like you might be able to combine the experimental parse with array.from().

import "array"
import "experimental/json"

data = "{\"_id\": \"masterSamples\",\"_rev\": \"3-0d9d8777759e681c780688a6051a41e9\",\"masterSamples\": [{\"ProductCode\": \"PS000607\",\"FaultCode\": 8530,\"FaultDesc\": \"default 8530\"},{\"ProductCode\": \"PS000807\",\"FaultCode\": 7330,\"FaultDesc\": \"default 7330\"},{\"ProductCode\": \"PS000307\",\"FaultCode\": 7130,\"FaultDesc\": \"default 7130\"}]}"
samples = json.parse(data: bytes(v: data)).masterSamples
array.from(rows: samples)

This gave me this result:

Result: _result
Table: keys: []
             FaultCode:float        FaultDesc:string      ProductCode:string
----------------------------  ----------------------  ----------------------
                        8530            default 8530                PS000607
                        7330            default 7330                PS000807
                        7130            default 7130                PS000307
1 Like