HTTP & JSON jsonSetString

$jsonSetString[]

Sets a key to a string value in the current JSON object, explicitly forcing the value type to string regardless of its content.

Syntax
$jsonSetString[key;value]

Parameters

Parameter Type Required Default Description
key string check_circle Required The key name to set in the JSON object. Supports dot notation for nested keys.
value string check_circle Required The value to assign to the key. Always stored as a JSON string, even if it looks like a number or boolean.

Return Value

void

Modifies the JSON object in-place. Creates the key if it does not exist, updates it if it does. The value is always stored as a string type.

$jsonSetString forces the value to be stored as a JSON string type. This is important when you need to preserve leading zeros in IDs, ensure phone numbers aren’t parsed as integers, or when an API expects a string-typed field. In contrast, $jsonSet infers the type from the value content.

Examples

Force numeric-looking value as string

$json[]
$jsonSetString[id;00123]
$jsonStringify[]
// Output: {"id":"00123"} (string, not number 123)

Set a boolean-looking value as string

$jsonParse[{"config":{}}]
$jsonSetString[config.enabled;true]
$jsonStringify[]
// Output: {"config":{"enabled":"true"}}

Prevent type coercion in API payloads

$jsonParse[$httpResult]
$jsonSetString[phone;+1234567890]
$jsonSetString[zipCode;90210]
$httpPost[https://api.example.com/update;{"Content-Type":"application/json"};$jsonStringify[]]