|
<< Click to Display Table of Contents >> Navigation: 3. Script Language > JSON - Parser > Parser-Operations > !Object Operations > PSJ. - JSON Operations |
SPR Script Language
PSJ.DelKey
Removes a key from a JSON object at a specified path.
Intention
The PSJ.DelKey command in SPR removes a key from a JSON object located at a given path ($$PATH) within a JSON document identified by $$DOC). Optionally, it returns a status code in $$RET to indicate success or failure. It’s like instructing your robot to snip a specific branch off an object in your JSON structure.
For example, removing "key" from "root.object.key" in document 100 deletes that key-value pair from the object at "root.object".
Illustration
📝 Remove a Key: PSJ.DelKey|100|root.object.key removes the "key" from the object at "root.object".
📝 With Status: PSJ.DelKey|200|data.info.name|$$STAT removes "name" from "data.info" and stores the status in $$STAT.
Syntax
PSJ.DelKey|$$DOC|$$PATH[|$$RET]
Parameter Explanation
P1 - $$DOC - (Variable, Numeric)
The identifier of the JSON document (e.g., $$DOC as "100"). Must be a valid document. Required.
P2 - $$PATH - (Variable, String)
The dot-separated path to the key in the JSON document (e.g., $$PATH as "root.object.key"). Must point to a key in an object. Required.
P3 - $$RET - (Variable, Numeric, Optional)
The variable to store the status code (e.g., $$RET as "$$STAT"). Returns 0 for success or a positive value indicating an error. If omitted, the status is returned but not stored.
Examples
'***********************************
' Sample 1: Remove a Key
PSJ.DelKey|100|root.object.key
' Removes "key" from the object at "root.object" in document 100
MBX.Ready
'***********************************
' Sample 2: Remove Key with Status
PSJ.DelKey|200|data.info.name|$$STAT
' Removes "name" from "data.info" and checks status
IF $$STAT <> 0 THEN PRT.Error: $$STAT
MBX.Ready
Remarks
- $$RET returns 0 for success; non-zero values indicate errors (e.g., path not found, not an object, or key not present).
- Use PSJ.ErrCode for detailed error information if $$RET is not 0.
Limitations
- $$DOC must be a valid JSON document identifier.
- $$PATH must point to a key within an object; it cannot target array elements or non-object nodes.
See also: