Advanced

JSON to lua 0 index problem

JSON to lua 0 index problem
June 30, 2016 12:28PM
There is a problem if you use 0 as a index in a table in JSON.
LUA tables starts with index 1 and PHP from the backend start with 0.
There is conversion code so the indexes are correct but it might result unintended results because PHP autoconverts strings to integers.
If you index with a "0" string in JSON it will be converted to 0 int in PHP and the code that fixes indexes will be triggers and you will get a ordered list
Look at the examples below. There will be no fix because it it hard to do in PHP for a unusual case and it can be fixed with different config format.

JSON config followed by lua Print of the same data
"dists":{"0":1,"10":1,"20":0}

[dists] => Array
(
[1] => 1
[2] => 1
[3] => 0
)

"dists":{"0.00000000001":1,"10":1,"20":0}

[dists] => Array
(
[0.00000000001] => 1
[20] => 0
[10] => 1
)
Re: JSON to lua 0 index problem
July 04, 2016 02:47AM
Does it work correctly if "0" is not the first item? For example:

"dists":{"10":1,"0":1,"20":0}
Re: JSON to lua 0 index problem
July 04, 2016 11:03AM
Have not tested but I think so. The { elements are not ordered
Sorry, you do not have permission to post/reply in this forum.