»jsonencode Function

jsonencode encodes a given value to a string using JSON syntax.

The JSON encoding is defined in RFC 7159.

This function maps Packer language values to JSON values in the following way:

Packer typeJSON type
stringString
numberNumber
boolBool
list(...)Array
set(...)Array
tuple(...)Array
map(...)Object
object(...)Object
Null valuenull

Since the JSON format cannot fully represent all of the Packer language types, passing the jsonencode result to jsondecode will not produce an identical value, but the automatic type conversion rules mean that this is rarely a problem in practice.

»Examples

> jsonencode({"hello"="world"})
{"hello":"world"}

»Related Functions

  • jsondecode performs the opposite operation, decoding a JSON string to obtain its represented value.