Versions Compared

Key

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

...

Syntax

Code Block
Result = SRP_JSONJson(Handle, "STRINGIFYStringify", Style)

Returns

The JSON output.

Parameters

ParameterDescription
HandleHandle to a JSON Entity. Required.
StyleThe formatting style of the final output: Fast, DropNulls, or Styled. Optional.

Remarks

The STRINGIFY Stringify service turns a JSON entity into standard JSON, which is just a string containing the JSON contents that can be consumed by clients that are JSON aware, particularly Javascript. The Style parameter allows you to control how the JSON looks. The "Styled" option is a tad slower to build but it puts line breaks and indents in the JSON to make it human readable. The "Fast" option uses no line breaks at all, making it faster to build and smaller. Smaller JSON means less waiting when it's sent over the internet. To make the fast JSON even smaller (and a tiny bit faster), you can use the "DropNulls" option which is the same as "Fast" but with all instances of 'null' replaced with no text at all. Technically, it's not standard JSON to omit nulls, but all browsers seems to handle it just fine. The default style is "Fast".

Example

Code Block
// Create a JSON array, add elements to it, and stringifyStringify it fast
If SRP_JSONJson(ArrayHandle, "NEWNew", "ARRAY") then
   SRP_JSONJson(ArrayHandle, "ADDVALUEAddValue", "12345")
   SRP_JSONJson(ArrayHandle, "ADDVALUEAddValue", 67890, "NUMBER")
   SRP_JSONJson(ArrayHandle, "ADDVALUEAddValue", 1, "BOOLEAN")
   JSON = SRP_JSONJson(ArrayHandle, "STRINGIFYStringify", "FAST")
   SRP_JSONJson(ArrayHandle, "RELEASERelease")
end

// Create a JSON object, add members to it, and stringifyStringify it pretty
If SRP_JSONJson(ObjectHandle, "NEWNew", "OBJECT") then
   SRP_JSONJson(ObjectHandle, "SETVALUESetValue", "name", "John Doe")
   SRP_JSONJson(ObjectHandle, "SETVALUESetValue", "city", "Washington D.C.")
   JSON = SRP_JSONJson(ObjectHandle, "STRINGIFYStringify", "STYLED")
   SRP_JSONJson(ObjectHandle, "RELEASERelease")
end

See Also

PARSEParse