Skip to content
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

[Bug] Util.JsonEncode considers tables with index 0 as arrays #348

Open
my-name-is-samael opened this issue Jul 4, 2024 · 0 comments
Open
Labels
bug Something isn't working good first issue Good for newcomers

Comments

@my-name-is-samael
Copy link

Have you read our FAQ/Wiki/#before-you-ask ?
Yes

Describe the bug
When I use Util.JsonEncode on a LUA Object with index 0 (followed by 1, 2, 3, etc), the returned JSON string represents an array.
LUA "arrays" (as I understand with ipairs) have indices starting with 1, so my example should be considered as an object when it is converted to JSON.

To Reproduce
Steps to reproduce the behavior:

  1. Execute following code:
print(Util.JsonEncode({
    [0] = "a",
    [1] = true,
    [2] = 0.1
}))
  1. The result string is ["a",true,0.1] but should be {0:"a",1:true,2:0.1}

Expected behavior
When passing to Util.JsonEncode a table containing an index out of the range 1-N (or present in subobjects), it should return an object and not an array

Desktop (please complete the following information):

  • OS Windows 11 Pro
  • BeamMP Server v3.4.1
@lionkor lionkor transferred this issue from BeamMP/BeamMP Jul 4, 2024
@lionkor lionkor added good first issue Good for newcomers bug Something isn't working labels Jul 4, 2024
@jimkoen jimkoen self-assigned this Jul 19, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working good first issue Good for newcomers
Projects
None yet
Development

No branches or pull requests

3 participants