HTTP & JSON json

$json[]

Creates a JSON object with an optional initial value. If no value is provided, an empty JSON object is created.

Syntax
$json[value?]

Parameters

Parameter Type Required Default Description
value json Optional An optional JSON object or string to initialise the internal JSON structure. Accepts valid JSON literals (objects, arrays, strings, numbers, booleans, null) or references to variables containing JSON.

Return Value

void

Initialises the internal JSON context. Subsequent JSON functions operate on this structure.

The $json function is the entry point for all JSON operations. It initialises an internal JSON context that all subsequent JSON functions operate on. If called without a value, an empty object {} is created. If a value is provided, it must be valid JSON. The internal JSON structure persists until it is cleared with $jsonClear or overwritten by calling $json again.

Examples

Create an empty JSON object

$json[]
$jsonSet[name;John]
$jsonSet[age;30]
Description: $jsonStringify[]

Create a JSON object from a literal

$json[{"name":"John","age":30}]
Name: $jsonValue[name]

Create nested JSON from a variable

$var[data;{"users":[{"id":1},{"id":2}]}]
$json[$var[data]]
Count: $jsonArrayCount[users]

Related Functions

$jsonparse $jsonset $jsonvalue $jsonclear