There are 2 problems I have observed with the JsonExport command from the JSON library included in LC8.
First, numbers are not always correctly handled.
Second, there is no way to generate a JSON array. Other JSON libraries generally assume that an array that has all numeric keys should be a JSON array.
Example 1 (Array into JSON)
Code: Select all
put 3.1415 into tData["somekey"]
put "12345abcde" into tData["otherkey"]
put "abc" into tData["array"][1]
put "def" into tData["array"][2]
put JsonExport(tData) into field "a3"
Code: Select all
{"somekey": 3.1415, "otherkey": "12345abcde","array": ["abc","def"]}
Code: Select all
{"somekey": "3.1415","otherkey": "12345abcde","array": {"1": "abc","2": "def"}}
--if I use this instead I get the correct result: add 3.1415 to tData["somekey"]
--the JSON array called "array" is presented as just another JSON
Example 2: JSON to Array and Back
in field "a4" is:
Code: Select all
{"somekey": 3.1415, "otherkey": "12345abcde","array": ["abc","def"]}
Code: Select all
put field "a4" into tJson
put JsonImport(tJson) into tArray
put JsonExport(tArray) into field "a5"
Code: Select all
{"somekey": 3.1415,"otherkey": "12345abcde","array": {"1": "abc","2": "def"}}
--tArray looks the same in the variable viewer as tData that is created in the first example
--the JSON array still does not get produced