All Products
Search
Document Center

CDN:JSON functions

Last Updated:Apr 01, 2026

Use these functions to encode dictionary objects into JSON strings and decode JSON strings back into dictionaries.

json_enc

Syntaxjson_enc(d)
DescriptionEncodes a dictionary object into a JSON string.
Parametersd: The dictionary object to encode.
Return valueA JSON-encoded string on success, or false on failure.

Example:

var_a = []
var_b = ['v1', 'v2']
set(var_a, 'k1', 'v1')
set(var_a, 'k2', var_b)
var_c = '{"k1":"v1","k2":["v1","v2"]}'
say(concat('json_enc=', json_enc(var_a)))
say(concat('json_dec=', get(json_dec(var_c), 'k1')))

Output:

json_enc={"k1":"v1","k2":["v1","v2"]}
json_dec=v1

json_dec

Syntaxjson_dec(s)
DescriptionDecodes a JSON string into a dictionary.
Parameterss: The JSON string to decode.
Return valueA dictionary on success, or false on failure.
Note

A numeric string such as "123" decodes into a variable of the number type. Before performing operations on the decoded value (such as getting a value), use the type function to check its type.

The following examples show two scenarios: decoding a numeric string and decoding a JSON object.

Example 1: Decoding a numeric string

var_c = '123'
type_var_c = type(json_dec(var_c))
if eq(type_var_c, 'table') {
  say(concat('json_dec=', get(json_dec(var_c), 'k1')))
} else {
  say(type_var_c)
}

Output:

number

Example 2: Decoding a JSON object

var_c = '{"k1":"v1","k2":["v1","v2"]}'
type_var_c = type(json_dec(var_c))
if eq(type_var_c, 'table') {
  say(concat('json_dec=', get(json_dec(var_c), 'k1')))
} else {
  say(type_var_c)
}

Output:

json_dec=v1