Page History
...
To avoid dealing with handles, SRP JsonX relies on state. Under the hood, SRP JsonX maintains a stack of JsonX documents. Whenever you start a JsonX document, that document is placed at the top of the stack and becomes the current document. Every document has a current path, which defaults to the root of the document. These two states are important to navigating, updating, and building json documents with SRP JsonX. When you are done with a document, you call SRP_JsonX_End, which removes the current document from memory and makes the previous document on the stack the current one.
...
There are two routines for creating new json documents: SRP_JsonX_Begin and SRP_JsonX_BeginString. SRP_JsonX_Begin creates a new json data structure that can be built, navigated, and modified at will. SRP_JsonX_BeginString creates a new json string that can only be built top down.
...
In this example, we start a new document called MyDocument. The document name is for debugging purposes only, so use whatever you want. The second parameter defines the new document's root. It must be "{" or "[". Note that this new document is now the active one and it's current path is pointing to the root of the document.
SRP_JsonX is a special routine whose parameters are interpreted according to the current state. The comments above help explain how SRP_JsonX makes its decisions. As you can see,
To get the final json output, we call SRP_JsonX_End. This routine does two things. It optionally returns the current document as a json string, then it removes the current document from memory and makes the previous document on the stack the current one.
...
Example 2 makes the same json as Example 1, but this time we started with SRP_JsonX_BeginString. Note how the calls to SRP_JsonX don't behave any differently. The only difference is that behind the scenes, SRP JsonX is producing pretty json text directly. If you know you are making a json string and you plan to build it from the top down, then SRP_JsonX_BeginString will be faster.
Parsing Json
...
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.
When an SRP JsonX method fails, you can call SRP_JsonX_Error immediately afterwards to get a detailed error message.
...
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. |
SRP_JsonX_End | Ends the current document, optionally returning json. |
SRP_JsonX_Error | Gets the last known error. |
SRP_JsonX_Get | Gets an elements element's value or json. |
SRP_JsonX_Go | Makes an element the new current element. |
SRP_JsonX_GoBack | Makes the parent of the current element the new current element. |
SRP_JsonX_GoRoot | Makes the document's root the current element. |
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. |
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_Values | Gets all an object's or array's values. |
...