Parses json into a new document.

Syntax

SRP_JsonX_Parse(Name, Json)

Returns

1 if successful, 0 if there were parsing errors. Call SRP_JsonX_Error for the parsing error.

Parameters

ParameterDescription
NameThe name of the new document, used for debugging purposes only
JsonThe Json to be parsed.

Remarks

SRP_JsonX_Parse creates a new document from the given json. If there was already an active document, that one is placed on the stack and this one becomes the active document. This routine returns 1 if there were no parsing errors or 0 if there were. In the latter case, call SRP_JsonX_Error to get the parsing error. Even if there are parsing errors, the partially parsed document is the new active document.

The Name parameter can be anything you want as it is only used for debugging purposes. The name will appear when calling SRP_JsonX_State or SRP_JsonX_Trace.

Every call to SRP_JsonX_Parse must eventually be paired with a call to SRP_JsonX_End, even if there were parsing errors.

Examples

$insert SRPJSONX

Json  = '{'
Json := '    "employees": ['
Json := '        {'
Json := '            "firstname": "John",'
Json := '            "lastname": "Doe",'
Json := '            "age": 21'
Json := '        },'
Json := '        {'
Json := '            "firstname": "Anna",'
Json := '            "lastname": "Smith",'
Json := '            "age": 32'
Json := '        },'
Json := '        {'
Json := '            "firstname": "Peter",'
Json := '            "lastname": "Jones",'
Json := '            "age": 43'
Json := '        }'
Json := '    ],'
Json := '    "nums": [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],'
Json := '    "active": true,'
Json := '    "alwaysnull": null,'
Json := '    "alwaysstring": "4.321"'
Json := '}'
 
Success = SRP_JsonX_Parse('MyDocument', Json)
If Success EQ 0 then
    Error = SRP_JsonX_Error()
    debug
end else
	Value = SRP_JsonX_Get('employees[2].lastname')
end
SRP_JsonX_End()
  • No labels