JSON.ENCODE

JSON.ENCODE encodes a context reference into JSON.

Function category: JSON

This function can only take a context reference (i.e. data.vehicle), which means that passing map literals directly into the function won't work.

To perform the opposite operation, decoding a given JSON, use JSON.DECODE‚Äč

Syntax

JSON.ENCODE(arg1)

Arguments

Description

arg1

A string.

Examples

Example 1: Encode information as JSON

Let's say we receive the following vehicle information:

{
"data":{
"vehicle":{ "model": "prototype", "serial_numbers": [1, 2, 3] }
}
}

If we want to pass along that vehicle information as a JSON string, we can use JSON.ENCODE:

JSON.ENCODE(data.vehicle)

This returns the following:

'{"model": "prototype", "serial numbers": [1,2,3]}'