JBUILD()

Top  Previous  Next

 

The JBUILD() function constructs a JSON string from a data collection.

 

 

Format

 

JBUILD(var)

JBUILD(var, mode)

 

where

 

varis a data collection variable.

 

modeis an optional additive value specifying the manner in which the JSON string is formed.
JB$INVALIDSave invalid data types (e.g. file variables) as null.
JB$NULLSave empty strings as "null".
JB$NUMSave numeric strings as numbers, where possible.
JB$SQUOTE.NAMEUse single quotes on element names.
JB$NOQUOTE.NAMEOmit quotes on element names.
JB$SQUOTE.VALUEUse single quotes on string values.
JB$NOQUOTE.VALUEOmit quotes on string values.

 

 

The JBUILD() function transforms the content of a QMBasic data collection variable into a JSON (JavaScript Object Notation) string. If successful, the JSON string is returned as the value of the function and the STATUS() function returns zero.

 

If the JBUILD() function fails, a null string is returned and the STATUS() function returns ER$BUILD.ERROR. Failure will occur if the data collection contains any elements that do not have a JSON representation such as a file variable.

 

 

Example

 

VAR = JPARSE(JSON.STRING)

VAR{'client/name'} = NEW.CLIENT.NAME

JSON.STRING = JBUILD(VAR)

 

The above program fragment parses a JSON string into a data collection variable, modifies the client name element and rebuilds the JSON representation of the modified data.

 

 

See also:

Data collections, JPARSE()