JsonToText Function

Action

Gets the string representation of a JSON object or a JSON array.

The properties of an object are sorted ascending by their name. The elements of an array are sorted ascending by their index. This string representation contains no whitespaces for formatting.

Include file

Json.bdh

Syntax

JsonToText( in handle : number,
            out text  : string ): boolean;
Parameter Description
handle Valid handle to a JSON object or a JSON array
text The string representation of the given JSON object or the given JSON array

Return value

  • true if successful
  • false otherwise

Example

transaction TMain
var
  jsonText              : string;
  jsonArray, jsonObject : number;
begin
  jsonArray := JsonParse("[0,1,2,3,4]");
  JsonToText(jsonArray, jsonText);
  Print("JSON array: " + jsonText);
  JsonFree(jsonArray);
  
  jsonObject := JsonParse("{\"name\":\"new object\",\"id\":1}");
  JsonToText(jsonObject, jsonText);
  Print("JSON object: " + jsonText);
  JsonFree(jsonObject);
end TMain;

Output


JSON array: [0,1,2,3,4]
JSON object: {"id":1,"name":"new object"}