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

JSON stringify - unespected behavior - sorting keys by default #99852

Open
orfaust opened this issue Nov 29, 2024 · 1 comment
Open

JSON stringify - unespected behavior - sorting keys by default #99852

orfaust opened this issue Nov 29, 2024 · 1 comment

Comments

@orfaust
Copy link

orfaust commented Nov 29, 2024

Tested versions

Reproducible in v4.3.stable.official [77dcf97]

System information

Windows 10 - v4.3.stable.official [77dcf97]

Issue description

This is not a bug actually.
Unespected and, in my opinion, uwanted behavior of the JSON.stringify method.
Gave me issues because I was storing a very basic list of ordered high-scores in a dictionary, with names as keys and scores as values.
Initially I thought there was a problem with my sorting algorythm, so it took me a while to find out that the method was resorting my data.
In my opinion the sort_keys: bool parameter should be false by default

Steps to reproduce

example code:

var data = {
"b": 1000,
"a": 200
}
print(data)
print(JSON.stringify(data))

will print

{ "b": 1000, "a": 200 }
{"a":200,"b":1000}

Minimal reproduction project (MRP)

json-stringify.zip

@Mickeon
Copy link
Contributor

Mickeon commented Nov 30, 2024

Note that the JSON format does not guarantee insertion order, so the the alphabetical sorting may be enabled by default to guarantee some form of consistency when retrieving data back as a Dictionary.

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

No branches or pull requests

3 participants