PSJ. - JSON Operations

<< Click to Display Table of Contents >>

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

PSJ. - JSON Operations

PSJ.GetValStr

PreviousTopNext


SPR Script Language

 

PSJ.GetValStr

Retrieves a value at a specified path as a string, converting any type.

 

Intention

 

The PSJ.GetValStr command in SPR retrieves the value of a node at a specified path ($$PTH) within a JSON document identified by $$DCH), converting it to a string regardless of its original type (e.g., number, boolean, null). Optionally, it stores the result in a variable specified by $$RTN. This command is ideal for extracting and standardizing values from a JSON structure as strings.

 

For example, retrieving the value at "root.age" from document 100 might return "25" (converted from a number) or "true" (converted from a boolean).

 

Illustration

📝 Get a Value as String: PSJ.GetValStr|100|root.age retrieves the value at "root.age" as a string from document 100.
📝 With Return Variable: PSJ.GetValStr|200|data.flag|$$VAL stores the value at "data.flag" as a string in $$VAL.

 

Syntax

 

PSJ.GetValStr|$$DCH|$$PTH[|$$RTN]

 

Parameter Explanation

 

P1 - $$DCH - (Variable, Numeric)

The identifier of the JSON document (e.g., $$DCH as "100"). Required.

 

P2 - $$PTH - (Variable, String)

The dot-separated path to the node in the JSON document (e.g., $$PTH as "root.age"). Required.

 

P3 - $$RTN - (Variable, String, Optional)

The variable to store the retrieved string value (e.g., $$RTN as "$$VAL"). If omitted, the string is returned but not stored in a variable.

 

Examples

 

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

' Sample 1: Retrieve a Number as String

PSJ.GetValStr|100|root.age

' Retrieves the value at "root.age" as a string (e.g., "25") from document 100

MBX.Ready

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

' Sample 2: Retrieve and Store a Boolean as String

PSJ.GetValStr|200|data.flag|$$VAL

' Stores the value at "data.flag" as a string (e.g., "true") in $$VAL

MBX.The flag is: $$VAL

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

 

Remarks

 

- Converts any JSON type (string, number, boolean, null) to its string representation.

- For arrays, the path must include a valid index (e.g., "array.0").

- Returns an empty string if the path is not found or an error occurs; use PSJ.ErrCode for error details.

 

Limitations

 

- $$DCH must be a valid document handle.

- $$PTH must resolve to an existing node.

 

See also:

 

PSJ.GetStr

PSJ.ErrCode