This topic describes the syntax, description, parameters, return values, and examples of JSON functions.
json_enc
This function is described as follows:
- Syntax:
json_enc(d)
- Description
You can call this function to encode a dictionary object into a JSON string.
- Parameters
d: the dictionary object to be encoded.
- Return values
This function returns a JSON-encoded string upon a success and returns
false
upon a failure. - Examples
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
This function is described as follows:
- Syntax:
json_dec(s)
- Description
You can use this function to decode a JSON string.
- Parameters
s: the JSON string to be decoded.
- Return values
This function returns the decoded string upon a success and returns
false
upon a failure. - Examples
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