$GetJSON
Reads a text file containing a JSON structure and places its compressed contents in a variable.
Syntax
$getjson(<a variable>, <a document name>)
Parameters
| a variable | a variable, a field name or a form field name receiving the contents of the document |
| a document | a valid Zim:X document name pointing to a JSON structured text file |
Return Value
Returns $True (1) when the operation was successful and the resulting compressed string fit the destination variable or $False (0) otherwise.
Comments
The receiving variable name must be large enough to hold the entire compressed JSON text file. It will also contain the string “ZIMJSON” as an indication that the text was obtained from a text file and that it is compressed.
The function $GetJSON validates the JSON syntax present in the document and this is one of the conditions for returning a $True value.
It can also be used to compress any other kind of text file. However, it will return $False because it would not be a properly formed JSON structure. That’s why it’s very important to test the result value of the function.
Considering that ZIM variables can be at most 32 Kb in size, the resulting compressed string should not reach that limit.
Example
Given the following JSON file pointed by a ZIM:X document called MyDocument:
{
"employee": {
"name": "sonoo",
"salary": 56000,
"married": true
}
}The command:
OUT $GetJSON(MyVar3000, MyDocument)
Will return:
ZIMJSON = {"employee":{"name":"sonoo","salary":56000,"married":true}}