Gets an element's value.

Syntax

Value = SRP_JsonX_Get(Path, DefaultIfNull)

Returns

The element's value if found, null otherwise

Parameters

ParameterDescription
PathPath to an elements whose value to get.
DefaultIfNullThe value to return if the element is null or was not found. Optional. Default is ""

Remarks

SRP_JsonX_Get gets the value of the element pointed to by Path. See Paths for more details. The chart below shows how different types are returned.

TypeReturned
true
1
false
0
null
DefaultIfNull

Number

String

The number or string's value, as is.

Object

Array

A json formatted string.

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()
end else
    Value = SRP_JsonX_Get('employees[2].lastname')
end
SRP_JsonX_End()
  • No labels