Page 1 of 1
JSONToArray Bug
Posted: Thu Jan 20, 2022 3:26 am
by TR-i
When converting a JSON string to a Livecode array, empty Javascript arrays are converted to plain empty variables. This causes errors when converting back to JSON (then parsing in Javascript). Javascript expects an empty array to be 2 brackets... []. Executing code will no longer see the variable as an array.
Re: JSONToArray Bug
Posted: Thu Jan 20, 2022 5:34 pm
by andresdt
Hi @TR-i
Yesterday when we read your post, at first it seemed to us that it was not a mistake
Rather, it was about how data is represented in LiveCode vs JavaScript. But then we wonder if it would be possible to represent an empty array in LiveCode.
Well, if you can:
This would fix the problem with [] representing arrays in JS. But we were missing the empty JS objects {}.
And that's it, this way we can prevent JSON arrays and objects from being converted to plain variables.
So we have updated our JSON handling library with this feature.
You can find it here:
https://ferruslogic.com/product/PhotonJSON
If PhotonJSON helps you solve your problem and if you think the project deserves it. Leave us a star on github, to continue developing this library.
https://github.com/Ferruslogic/PhotonJSON
Re: JSONToArray Bug
Posted: Thu Jan 20, 2022 7:04 pm
by stam
very nice @andresdt!
Re: JSONToArray Bug
Posted: Thu Jan 20, 2022 8:30 pm
by andresdt
Thank you @Stam on behalf of myself and my partner @prometheus. For your words and for your star on Github

Re: JSONToArray Bug
Posted: Fri Jan 21, 2022 2:26 am
by TR-i
Converting JSON to array seems to be working correctly, but not back to JSON.
This going in: "list":{}
Becomes this when converted back to JSON: "list":{"1":"","":""}
Re: JSONToArray Bug
Posted: Fri Jan 21, 2022 2:52 am
by andresdt
Re: JSONToArray Bug
Posted: Fri Jan 21, 2022 4:02 am
by andresdt
I have tried the example you provide and here it works OK
Code: Select all
put JSONStringify(JSONParser( "{"& quote &"list"& quote &":{}}" )) --> Returns {"list": {}}
Re: JSONToArray Bug
Posted: Fri Jan 21, 2022 6:42 am
by TR-i
Example should have been “list”:[] (brackets, not curly braces).
Looks like arrays (brackets) are being converted to objects (curly braces).
Re: JSONToArray Bug
Posted: Fri Jan 21, 2022 2:02 pm
by andresdt
TR-i wrote: ↑Fri Jan 21, 2022 6:42 am
Example should have been “list”:[] (brackets, not curly braces).
Looks like arrays (brackets) are being converted to objects (curly braces).
Hi @TR-i
You are using the latest version of the PhotonJSON library?
https://github.com/Ferruslogic/PhotonJS ... codescript
try with
Code: Select all
put JSONStringify(JSONParser( "{"& quote &"list"& quote &":[]}" )) --> {"list": []}
It worked well for me.
Please confirm whether or not you are using the PhotonJSON library. Since this was where this was fixed.
Re: JSONToArray Bug
Posted: Fri Feb 04, 2022 11:29 pm
by TR-i
Yes, using the latest.
Translating back and forth inside Livecode would obviously work. However, results are inconsistent when you actually hand the JSON to Javascript to translate back into objects.
Also, while I installed the library using the installer stack, standalone apps failed to find it.