You are viewing an old version of this page. View the current version.

Compare with Current View Page History

« Previous Version 3 Next »

Formats the given JSON Entity into a standardized JSON string.

Syntax

Result = SRP_Json(Handle, "Stringify", 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 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

// Create a JSON array, add elements to it, and Stringify it fast
If SRP_Json(ArrayHandle, "New", "ARRAY") then
   SRP_Json(ArrayHandle, "AddValue", "12345")
   SRP_Json(ArrayHandle, "AddValue", 67890, "NUMBER")
   SRP_Json(ArrayHandle, "AddValue", 1, "BOOLEAN")
   JSON = SRP_Json(ArrayHandle, "Stringify", "FAST")
   SRP_Json(ArrayHandle, "Release")
end

// Create a JSON object, add members to it, and Stringify it pretty
If SRP_Json(ObjectHandle, "New", "OBJECT") then
   SRP_Json(ObjectHandle, "SetValue", "name", "John Doe")
   SRP_Json(ObjectHandle, "SetValue", "city", "Washington D.C.")
   JSON = SRP_Json(ObjectHandle, "Stringify", "STYLED")
   SRP_Json(ObjectHandle, "Release")
end

See Also

Parse

  • No labels