-
-
Notifications
You must be signed in to change notification settings - Fork 411
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
toJSON incorrectly stringifies object #1073
Comments
Indeed we need a new argument for this correct behavior. |
Also I would like to have abillity to disable json optimisation |
JSON optimisation? |
If there are same tables, |
This seems like a bug and should only happen for self-referencing tables. Please can you create a separate issue for this? i.e. this should not happen:
Relevant: e883f1c mtasa-blue/Server/mods/deathmatch/logic/lua/CLuaArgument.cpp Lines 811 to 825 in e11685c
|
I'm exactly about self-referencing tables. |
I want it just writes a copy of the table instead of the link to it. Something like this:
|
But how would a copy work? It's an infinite loop or I'm missing something? Nevermind. Seems like something we should add an option for. I propose we change toJSON to accept an |
I actually think it's a bug and only meant to be for truly self-referencing (recursive) tables — in this case I think we should fix the |
No shit, so thats what is causing MTA's famous double array JSON.. I see.. |
I made a small "investigation" and found the problem in Just look at 1387 and 1417-1418 mtasa-blue/vendor/json-c/json_object.c Lines 1381 to 1419 in 83ca27a
The authors of |
If I'm reading things right, that toJSON call triggers the toJSON function which calls WriteToJSONString, which calls WriteToJSONArray to explicitly create an array type json_object and then calls json_object_to_json_string_ext on that. The json-c code is doing exactly what you're asking it to do. This probably needs that extra array wrapping code removed. |
Describe the bug
When serializing a standalone object, the returned JSON puts it into an array. This is incorrect because the object is not in an array before serialization. An argument for correct behavior should solve the problem.
To reproduce
srun outputChatBox(toJSON ( { "dogs", cat = "hungry", mouse = "food", birds = 4 } ))
Expected behaviour
Command results: { "1": "dogs", "mouse": "food", "cat": "hungry", "birds": 4 } [string]
Actual behaviour
Command results: [ { "1": "dogs", "mouse": "food", "cat": "hungry", "birds": 4 } ] [string]
This should only be triggered by:
toJSON ( { { "dogs", cat = "hungry", mouse = "food", birds = 4 } } )
Version
MTA:SA Server v1.5.6-release-16345
Multi Theft Auto v1.5.6-release-18706
The text was updated successfully, but these errors were encountered: