JsonFree Function

Action

Deletes a JSON object or a JSON array from the memory. The JSON object or the JSON array does not consume memory any more. After calling the function JsonFree the properties and elements cannot be accessed any more.

This function also deletes all nested JSON objects and JSON arrays.

It is highly recommended to delete every JSON object and JSON array from the memory when it is not needed any more. For every call of JsonParse, JsonObjectCreate and JsonArrayCreate should be a call of JsonFree.

Include file

Json.bdh

Syntax

JsonFree( in handle : number ): boolean;
Parameter Description
handle Valid handle to a JSON object or a JSON array

Return value

  • true if successfully deleted
  • false otherwise

Example

transaction TMain
var
  jsonText                 : string;
  jsonObject, nestedObject : number;
begin
  WebParseDataBound(jsonText);
  WebPageUrl("http://mycompany.com/api/jsondata");
  jsonObject := JsonParse(jsonText);
  JsonGetObjectProperty(jsonObject, "nested object property", nestedObject);

  //jsonObject and nestedObject are still in memory and consume space
  JsonFree(jsonObject);
  //jsonObject is not in the memory any more
  //nestedObject is also deleted
  
  //nothing happens and the four functions return false
  JsonSetStringProperty(jsonObject, "StringProperty", "new string value");
  JsonSetStringProperty(nestedObject, "StringProperty", "new string value");
  JsonFree(jsonObject);
  JsonFree(nestedObject);
end TMain;