docs-v2/content/flux/v0.x/stdlib/json/encode.md

1.1 KiB

title description aliases menu weight flux/v0.x/tags introduced
json.encode() function The `json.encode()` function converts a value into JSON bytes.
/influxdb/v2.0/reference/flux/functions/json/encode/
/influxdb/v2.0/reference/flux/stdlib/json/encode/
/influxdb/cloud/reference/flux/stdlib/json/encode/
flux_0_x_ref
name parent
json.encode json
202
type-conversions
0.40.0

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

import "json"

json.encode(v: "some value")
// Returns [34 115 111 109 101 32 118 97 108 117 101 34]

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.