|
<< Click to Display Table of Contents >> Navigation: 3. Script Language > JSON - Parser > Parser-Operations > !Value Operations > PSJ. - JSON Operations |
SPR Script Language
PSJ.SetBool
Sets or creates a boolean value at a specified path in a JSON object.
Intention
The PSJ.SetBool command in SPR sets or creates a boolean value ($$VAL) at a specified path ($$PTH) within a JSON document identified by $$DCH. Optionally, it stores the operation status in a variable specified by $$RTN. This command is useful for updating or initializing boolean properties in a JSON structure.
For example, setting "person.address.isCommercial" to 1 (true) in document 100 creates or updates the boolean value at that path.
Illustration
📝 Set Boolean: PSJ.SetBool|100|person.address.isCommercial|1 sets "isCommercial" to true.
📝 With Status Check: PSJ.SetBool|200|settings.active|0|$$STA sets "active" to false and stores the status in $$STA.
Syntax
PSJ.SetBool|$$DCH|$$PTH|$$VAL[|$$RTN]
Parameter Explanation
P1 - $$DCH - (Variable, Numeric)
The handle of the JSON document (e.g., $$DCH as "100"). Required.
P2 - $$PTH - (Variable, String)
The dot-separated path where the boolean value should be set (e.g., $$PTH as "person.address.isCommercial"). Required.
P3 - $$VAL - (Variable, Numeric)
The boolean value to set (e.g., $$VAL as "0" for false, "1" for true). Non-zero values are interpreted as true. Required.
P4 - $$RTN - (Variable, Numeric, Optional)
The variable to store the status code (e.g., $$RTN as "$$STA"). Returns non-zero on success, 0 on failure. If omitted, the status is returned but not stored.
Examples
'***********************************
' Sample 1: Set a Boolean Value
PSJ.SetBool|100|person.address.isCommercial|1
' Sets "isCommercial" to true in document 100
MBX.Ready
'***********************************
' Sample 2: Set Boolean with Status Check
PSJ.SetBool|200|settings.active|0|$$STA
' Sets "active" to false and checks status
IVV.$$STA!0
MBX.Boolean set successfully
ELS.
PRT.Error setting boolean: $$STA
EIF.
'***********************************
Remarks
- Creates intermediate objects in $$PTH if they don’t exist.
- Overwrites existing non-array values at the final key; arrays are not supported.
- Returns non-zero on success, 0 on failure; use PSJ.ErrCode or PSJ.ErrMsg for error details.
Limitations
- $$DCH must be a valid document handle.
- $$PTH must be a valid object path; array indices (e.g., "list[0]") are not supported.
- Fails if the path conflicts with an existing array.
See also: