PSJ. - JSON Operations

<< Click to Display Table of Contents >>

Navigation:  3. Script Language > JSON - Parser > Parser-Operations > !Utility and Conversion >

PSJ. - JSON Operations

PSJ.GetLastResultS

PreviousTopNext


SPR Script Language

 

PSJ.GetLastResultS

Gets the last primary STRING result produced by the JSW library.

 

Intention

 

The PSJ.GetLastResultS command retrieves the most recent STRING result that was stored internally by the JSW library. When commands call the internal W_JSON_HandleResultOutput helper, it stores both the primary WSTRING result and a STRING version (typically converted to UTF-8). This command fetches that stored STRING version directly, optionally storing it in $$RES. This is often the same as the UTF-8 conversion obtained via PSJ.GetLastResultW, but provides direct access to the library's stored STRING representation.

 

Illustration

📝 Retrieve last stringified result:
PSJ.Parse|'{"a":1}'|$$DOC
PSJ.ToString|$$DOC|$$STR_OUTPUT // Store direct output (UTF-8 STRING)
PSJ.GetLastResultS|$$LAST_S_RES // Retrieve the stored STRING version
Result: $$STR_OUTPUT and $$LAST_S_RES will typically both contain the string '{"a":1}'.

 

Syntax

 

PSJ.GetLastResultS[|$$RES]

 

Parameter Explanation

 

P1 - $$RES - (Variable, String, Optional)

The variable where the last standard STRING result will be stored. If omitted, the result is returned but not stored.

 

Technical Background

 

This command calls the W_JSON_GetLastSResult() function in the JSW library, which retrieves the value of the thread-local global gLastJSONSResult_S. This global variable is typically populated by the W_JSON_HandleResultOutput helper after it converts the primary WSTRING result using a function like `HTP_WideToUtf8`. The `CMD_1041` wrapper then returns this STRING directly or assigns it to the optional $$RES variable.

 

Examples

 

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

' Sample: Retrieve last STRING result explicitly

PSJ.Parse|'{"key":"value"}'|$$DOC

PSJ.GetKeys|$$DOC| |$$KEYS_STR ' GetKeys populates last results

PSJ.GetLastResultS|$$LAST_STR

PRT.Keys String: $$KEYS_STR ' Output: key

PRT.Last S Result: $$LAST_STR ' Output: key

PSJ.Free|$$DOC

MBX.Ready

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

 

Remarks

 

- This retrieves the last STRING result, which is often the UTF-8 version of the WSTRING result.

- The underlying storage is thread-local.

 

Limitations

 

- The value returned depends entirely on the last command that called the internal W_JSON_HandleResultOutput function and the success of the string conversion performed there.

 

See also:

 

PSJ.GetLastResultW