JSONToArray Bug
Moderator: Klaus
JSONToArray Bug
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
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
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:
Code: Select all
put empty in tArray[1]
Code: Select all
put empty in tArray[empty]
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
Be kind, we all have our own wars.
https://torocruzand.com/
https://torocruzand.com/
Re: JSONToArray Bug
Thank you @Stam on behalf of myself and my partner @prometheus. For your words and for your star on Github 

Be kind, we all have our own wars.
https://torocruzand.com/
https://torocruzand.com/
Re: JSONToArray Bug
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":"","":""}
This going in: "list":{}
Becomes this when converted back to JSON: "list":{"1":"","":""}
Re: JSONToArray Bug
Was that with the library?




Be kind, we all have our own wars.
https://torocruzand.com/
https://torocruzand.com/
Re: JSONToArray Bug
I have tried the example you provide and here it works OK
Code: Select all
put JSONStringify(JSONParser( "{"& quote &"list"& quote &":{}}" )) --> Returns {"list": {}}
Be kind, we all have our own wars.
https://torocruzand.com/
https://torocruzand.com/
Re: JSONToArray Bug
Example should have been “list”:[] (brackets, not curly braces).
Looks like arrays (brackets) are being converted to objects (curly braces).
Looks like arrays (brackets) are being converted to objects (curly braces).
Re: JSONToArray Bug
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": []}
Please confirm whether or not you are using the PhotonJSON library. Since this was where this was fixed.
Be kind, we all have our own wars.
https://torocruzand.com/
https://torocruzand.com/
Re: JSONToArray Bug
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.
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.