Page History
...
Code Block | ||||
---|---|---|---|---|
| ||||
$insert SRPJSONX // Create a new document by parsing the json text SRP_JsonX_Parse('MyParsedDoc', Json) // Get the first employee's last name using SRP JsonX path syntax LastName = SRP_JsonX_Get('employees[1].lastname') // If our path points to an object or an array, we'll get the entire object or array as json text Employee = SRP_JsonX_Get('employees[1]') // Routines the get information donSRP_JsonX_Get doesn't change the current path. If we want to change the // current pathit, we use the Go routinesroutine. // Let's make the second employee the current path. SRP_JsonX_Go('employees[2]') // Now, if I want to get the last name, I must use a path relative to the current one LastName = SRP_JsonX_Get('lastname') // If I try to use a full path, I'll get a null value because all paths are relative to the current one // In this case, 'employees' doesn't exist inside 'employees[2]' LastName = SRP_JsonX_Get('employees[3].lastname') // We can go back up the json heirarchy one level at a time. This call makes 'employees' the current path 'employees' SRP_JsonX_GoBack() // Now I can get the third employee's last name LastName = SRP_JsonX_Get('[3].lastname') // We can get make the root the current path at any time SRP_JsonX_GoRoot() // When a value is null or not found, '' is returned by default. If you want a different value, // then set the DefaultIfNull parameter to your desired default Value = SRP_JsonX_Get('alwaysnull', 'This is null!!!') // We can also query the jsondocument for information (remember, we are currently at the root) NumEmployees = SRP_JsonX_Count('employees') MemberExists = SRP_JsonX_Has('employees[2].age') MemberNames = SRP_JsonX_Members('employees[3]') Type = SRP_JsonX_Type('alwaysbool') Numbers = SRP_JsonX_ValueValues('nums', ',') // We can also modify the jsondocument SRP_JsonX_Clear('nums') SRP_JsonX_Delete('employees[2]') SRP_JsonX_Sort() // All done with our parsed document.When we're done, we end it. Note that we can call this as a subroutine when we don't want json returned SRP_JsonX_End() |
Debugging
Given that SRP JsonX relies so heavily on state, it's important to give you the tools you need to troubleshoot issues. If you want to view the current state of SRP JsonX, call SRP_JsonX_State or SRP_JsonX_Trace. Both routines give you the stack and the current paths for each document on the stack. The difference between the two is that SRP_JsonX_Trace displays a message box whereas SRP_JsonX_State returns the stack as an @FM delimited array suitable for viewing in the debugger.
...
Routine | Description |
---|---|
SRP_JsonX | Adds elements to the current document based on the current path. |
SRP_JsonX_Begin | Creates a new document. |
SRP_JsonX_BeginString | Creates a new document that must be built in order. |
SRP_JsonX_Clear | Deletes all elements in an object or array. |
SRP_JsonX_Count | Gets the number of elements in an object or array. |
SRP_JsonX_Delete | Deletes an element and all it's children. |
SRP_JsonX_End | Ends the current document, optionally returning json. |
SRP_JsonX_Error | Gets the last known error. |
SRP_JsonX_Get | Gets an elements value or json. |
SRP_JsonX_Go | Makes an object or array the current path. |
SRP_JsonX_GoBack | Makes the parent of the current path the new current path. |
SRP_JsonX_GoRoot | Makes the document root the current path. |
SRP_JsonX_Has | Determines if an element exists. |
SRP_JsonX_Members | Gets all an object's member names. |
SRP_JsonX_Parse | Parses json into a new document. |
SRP_JsonX_Set | Sets a value or json. |
SRP_JsonX_Sort | Sorts an object's members by member name. |
SRP_JsonX_State | Gets the state of the stack and all its documents. |
SRP_JsonX_Trace | Shows the state of the stack and all its documents. |
SRP_JsonX_Type | Gets an element's type. |
SRP_JsonX_ValueValues | Gets all an object's or array's values. |
...