Skip to content

Fix #1073: toJSON incorrectly wraps single table in array - #5192

Open
0xSenior wants to merge 1 commit into
multitheftauto:masterfrom
0xSenior:fix/tojson-array-wrapping
Open

Fix #1073: toJSON incorrectly wraps single table in array#5192
0xSenior wants to merge 1 commit into
multitheftauto:masterfrom
0xSenior:fix/tojson-array-wrapping

Conversation

@0xSenior

Copy link
Copy Markdown

Problem:

  • toJSON({ key = value }) returned '[{...}]' instead of '{...}'
  • WriteToJSONString() always called WriteToJSONArray(), wrapping all results in a JSON array even for single table arguments

Solution:

  • Check if there is exactly one argument and it is a table (LUA_TTABLE)
  • If so, serialize it directly using WriteToJSONObject() instead of wrapping it in an array via WriteToJSONArray()
  • Otherwise, fall back to existing array behavior

Files changed:

  • Client/mods/deathmatch/logic/lua/CLuaArguments.cpp
  • Server/mods/deathmatch/logic/lua/CLuaArguments.cpp

This fix maintains backward compatibility for multiple arguments and non-table single arguments.

Summary

Motivation

Test plan

Checklist

  • Your code should follow the coding guidelines.
  • Smaller pull requests are easier to review. If your pull request is beefy, your pull request should be reviewable commit-by-commit.

Problem:
- toJSON({ key = value }) returned '[{...}]' instead of '{...}'
- WriteToJSONString() always called WriteToJSONArray(), wrapping
  all results in a JSON array even for single table arguments

Solution:
- Check if there is exactly one argument and it is a table (LUA_TTABLE)
- If so, serialize it directly using WriteToJSONObject() instead of
  wrapping it in an array via WriteToJSONArray()
- Otherwise, fall back to existing array behavior

Files changed:
- Client/mods/deathmatch/logic/lua/CLuaArguments.cpp
- Server/mods/deathmatch/logic/lua/CLuaArguments.cpp

This fix maintains backward compatibility for multiple arguments
and non-table single arguments.
Copilot AI lite review requested due to automatic review settings August 16, 2026 22:49

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants