json.parse() function

The json.parse() function is experimental and subject to change at any time. By using this function, you accept the risks of experimental functions.

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

*Function type: Type conversion*

  1. import "experimental/json"
  2. json.parse(
  3. data: bytes(v: "{\"a\":1,\"b\":2,\"c\":3}")
  4. )

Parameters

data

JSON data to parse.

*Data type: Bytes*

Examples

Parse and use JSON data to restructure a table
  1. import "experimental/json"
  2. data
  3. |> map(fn: (r) => {
  4. jsonData = json.parse(data: bytes(v: r._value))
  5. return {
  6. _time: r._time,
  7. _field: r._field,
  8. a: jsonData.a,
  9. b: jsonData.b,
  10. c: jsonData.c,
  11. }
  12. })