Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

Code Block
SRP_JsonX_BeginString(Name, StartingTokenInit, IsPretty)

Returns

Nothing. SRP_JsonX_BeginString always succeeds, but it can produce a warning if you don't pass "{" or "[" as the starting token. See SRP_JsonX_Error.

Parameters

ParameterDescription
NameThe name of the new document, used for debugging purposes only
InitInitial partial json. Must at lest StartingTokenDetermines if the new document's root is an object or an array. Can be "{" or "[", but can be more hardcoded json to start. Optional. Default is "{"
IsPrettySet to 1 to make the output human readable, set to 0 to make it compact. Optional.Default is 0

...

SRP_JsonX_BeginString creates a new document. If there was already an active document, that one is placed on the stack and this one becomes the active document. New documents must be initialized as a json object or json array, which is done via the StartingToken parameter. Set that parameter to

The Init parameter allows you to initialize the new document. At the very least, you should pass "{" to make start the root element document with an object as the root or "[" to make it an array.start the document with an array. However, you can pass as much json as you like to initalize the new document. The only thing you can't do is pass complete json since this routine is for starting a document you plan to build, not parse json. If, for example, you had a bunch of hardcoded json members you plan to return in a package, it is faster to pass json than to make a bunch of calls to SRP_JsonX to do the same thing. In the following example, we create a response initialized with some hardcoded members.

Code Block
SRP_JsonX_Begin('ErrorResponse', '{"status":200,"phrase":"OK","method":"GET","URL":"https:\\www.examples.com"')
    If Len(Errors) then
        SRP_JsonX('errors', '[')
        For Each Error in Errors using @FM
            SRP_JsonX(Error)
        Next Error
        SRP_JsonX(']')
    end
ErrorResponse = SRP_JsonX_End('Pretty')

This routine is only for situations where you will be building a json string in order. In fact, SRP_JsonX and SRP_JsonX_End are the only other routines you can use with this kind of document. Each call to SRP_JsonX behaves exactly the same as it always does, but instead of creating json structures in memory, each call appends json text to a string buffer. This is why you must specify the formatting via the IsPretty parameter at the beginning since formatting will be done with each call to SRP_JsonX. When you end the document by calling SRP_JsonX_End, the FormatOptions parameter will be ignored, and the json you built will be returned. If you know you are building json in order, this will be faster than using SRP_JsonX_Begin.

...