ComposeJSON()

Syntax

Result$ = ComposeJSON(#JSON [, Flags])
Description
Compose the given JSON data into a string. A string can be parsed back into JSON data using the ParseJSON() function.

Parameters

#JSON The JSON to compose.
Flags (optional) If set to #PB_JSON_PrettyPrint, the composed string will contain additional newline and whitespace for better readability. The extra whitespace is not significant to the JSON format. The output will have the same meaning to a JSON reader with or without this flag.

Return value

The JSON data as a string.

Remarks

The output string has the string format of the executable (Ascii or Unicode). JSON is generally encoded in UTF-8, so when writing the result string to a file or sending it to another application, it is advised to convert the string to UTF-8 before doing so.

Example

  If CreateJSON(0)
    Person = SetJSONObject(JSONValue(0))
    SetJSONString(AddJSONMember(Person, "FirstName"), "John")
    SetJSONString(AddJSONMember(Person, "LastName"), "Smith")
    SetJSONInteger(AddJSONMember(Person, "Age"), 42)
    
    Debug ComposeJSON(0, #PB_JSON_PrettyPrint)
  EndIf

See Also

SaveJSON(), ExportJSON(), ExportJSONSize(), ParseJSON()

Supported OS

All

<- ClearJSONMembers() - Json Index - CreateJSON() ->