PSJ. - JSON Operations

<< Click to Display Table of Contents >>

Navigation:  3. Script Language > JSON - Parser > Parser-Operations > !Node Operations >

PSJ. - JSON Operations

PSJ.ChildCount

PreviousTopNext


SPR Script Language

 

PSJ.ChildCount

Returns the number of child nodes for a given node.

 

Intention

 

The PSJ.ChildCount command in SPR determines the number of child nodes under a node identified by $$NODE). Optionally, it stores the result in $$RET. It’s like asking your robot to count how many branches a tree node has in your JSON structure.

 

For example, if a node with ID "100" has three children, it returns "3".

 

Illustration

📝 Get Child Count: PSJ.ChildCount|100 returns the number of children of node 100.
📝 With Result: PSJ.ChildCount|200|$$COUNT stores the number of children of node 200 in $$COUNT.

 

Syntax

 

PSJ.ChildCount|$$NODE[|$$RET]

 

Parameter Explanation

 

P1 - $$NODE - (Variable, Numeric)

The identifier of the node (e.g., $$NODE as "100"). Must be a valid node. Required.

 

P2 - $$RET - (Variable, Numeric, Optional)

The variable to store the result (e.g., $$RET as "$$COUNT"). Returns the number of child nodes (0 or greater) or 0 if the node is invalid or has no children. If omitted, the result is returned but not stored.

 

Examples

 

'***********************************

' Sample 1: Get Child Count

PSJ.ChildCount|100

' Returns the number of children of node 100

MBX.Ready

'***********************************

' Sample 2: Store Child Count

PSJ.ChildCount|200|$$COUNT

' Stores the number of children of node 200 in $$COUNT

PRT.Child Count: $$COUNT

MBX.Ready

 

Remarks

 

- $$RET returns the number of child nodes (0 or greater) or 0 if the node is invalid or has no children.

- Use PSJ.ErrCode for additional error information if needed.

 

Limitations

 

- $$NODE must be a valid node identifier.

 

See also:

 

PSJ.ChildAt

PSJ.ErrCode