json.encode() function

The json.encode() function converts a value into JSON bytes.

*Function type: Type conversion*

  1. import "json"
  2. json.encode(v: "some value")

This function encodes Flux types as follows:

  • time values in RFC3339 format
  • duration values in number of milliseconds since the epoch
  • regexp values as their string representation
  • bytes values as base64-encoded strings
  • function values are not encoded and produce an error

Parameters

v

The value to convert.

*Data type: Record | Array | Boolean | Duration | Float | Integer | String | Time | UInteger*

Examples

Encode all values in a column in JSON bytes

  1. import "json"
  2. from(bucket: "example-bucket")
  3. |> range(start: -1h)
  4. |> map(fn: (r) => ({
  5. r with _value: json.encode(v: r._value)
  6. }))