PSJ. - JSON Operations

<< Click to Display Table of Contents >>

Navigation:  3. Script Language > JSON - Parser > Parser-Operations > !File I/O >

PSJ. - JSON Operations

PSJ.SaveFile

PreviousTopNext


SPR Script Language

 

PSJ.SaveFile

Saves a JSON document to a file.

 

Intention

 

The PSJ.SaveFile command in SPR saves a JSON document, identified by $$DCH, to a file specified by $$FIL. Optionally, it stores the operation’s status in a variable specified by $$RTN. This command is key for exporting JSON data from SPR to a file on disk.

 

For example, saving document handle 100 to "C:\Data\output.json" writes the JSON structure to that file.

 

Illustration

📝 Save a JSON Document: PSJ.SaveFile|100|C:\Data\output.json saves document 100 to "output.json".
📝 With Status Check: PSJ.SaveFile|200|C:\Data\test.json|$$STA saves document 200 and stores the status in $$STA.

 

Syntax

 

PSJ.SaveFile|$$DCH|$$FIL[|$$RTN]

 

Parameter Explanation

 

P1 - $$DCH - (Variable, Numeric)

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

 

P2 - $$FIL - (Variable, String)

The path and filename where the JSON will be saved (e.g., $$FIL as "C:\Data\output.json"). Required.

 

P3 - $$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: Save a JSON Document

PSJ.SaveFile|100|C:\Data\output.json

' Saves document 100 to "output.json"

MBX.Ready

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

' Sample 2: Save with Status Check

PSJ.SaveFile|200|C:\Data\test.json|$$STA

' Saves document 200 to "test.json" and checks status

IVV.$$STA!0

 MBX.File saved successfully

ELS.

 PRT.Error saving file: $$STA

EIF.

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

 

Remarks

 

- Returns non-zero on success, 0 on failure (e.g., invalid handle, file permission issues).

- Use PSJ.ErrCode or PSJ.ErrMsg to diagnose failures if $$RTN is 0.

- The JSON is serialized to a string and written in UTF-16 or ASCII/UTF-8 format, depending on the system.

 

Limitations

 

- $$DCH must be a valid document handle.

- $$FIL must be a valid, writable file path; existing files will be overwritten.

 

See also:

 

PSJ.LoadFile

PSJ.ErrCode

PSJ.ErrMsg