Ends the current document, optionally returning json.

Syntax

Json = SRP_JsonX_End(FormatOption)

Returns

Json, if requested

Parameters

ParameterDescription
FormatOption"Pretty" to return pretty json. "Concise" to return fast json. "" to return no json. Optional. Default is "". 

Remarks

SRP_JsonX_End does two things. First, it converts the document into json text and returns it, but only if requested. To return pretty json, set FormatOption to "Pretty". To return compact json, set FormatOption to "Concise". Leave FormatOption blank to return no json at all. The second thing SRP_JsonX_End does is to remove the current document from memory and make the previous document the current one again. All calls to SRP_JsonX_Begin, SRP_JsonX_BeginString, and SRP_JsonX_Parse must be paired with a call to this routine to avoid memory leaks.

Note: If you used SRP_JsonX_BeginString to create the document, then calling this routine always returns json. Moreover, the json format is decided at the time of creation, so the FormatOption is ignored.

Examples

$insert SRPJSONX
 
SRP_JsonX_BeginString('DirectToString', '{', JsonxPretty$)
    SRP_JsonX('employees', '[')
        SRP_JsonX('{')
            SRP_JsonX('firstname', 'John')
            SRP_JsonX('lastname', 'Doe')
            SRP_JsonX('age', 21)
        SRP_JsonX('}')
        SRP_JsonX('{')
            SRP_JsonX('firstname', 'Anna')
            SRP_JsonX('lastname', 'Smith')
            SRP_JsonX('age', 32)
        SRP_JsonX('}')
        SRP_JsonX('{"firstname":"Peter", "lastname":"Jones", "age":43}')
    SRP_JsonX(']')
    SRP_JsonX('count', 4)
    SRP_JsonX('active', 1, 'Bool')
    SRP_JsonX('alwaysnull')
    SRP_JsonX('alwaysstring', 4.321, 'String')
Json = SRP_JsonX_End()
  • No labels