Skip to content

Automatic file saving reformats JSON file #105160

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

Open
ratkingsminion opened this issue Apr 8, 2025 · 8 comments · May be fixed by #105780
Open

Automatic file saving reformats JSON file #105160

ratkingsminion opened this issue Apr 8, 2025 · 8 comments · May be fixed by #105780

Comments

@ratkingsminion
Copy link

Tested versions

v4.4.1.stable.official [49a5bc7], but happens at least since Godot 4.4

System information

Windows 10, Godot 4.4

Issue description

I use an external program (for dialogues) that generates JSON files that I use directly in my Godot project. Godot decides to resave these JSON files from time to time and change the formatting. With Godot 4.4 not only the indents get changed, but also all number values get a ".0" if they were integer. This is bad for version control, and I really don't see the benefit of Godot saving and reformatting the JSON files at all.

Steps to reproduce

Create a JSON file from the outside and use it in a Godot project.

Minimal reproduction project (MRP)

N/A

@AThousandShips
Copy link
Member

Indentation is already tracked in:

So this should focus on the number formatting

@luksteph
Copy link

luksteph commented Apr 9, 2025

Hello, I think I'll try my hand at this one, if everyone's alright with that. I have an assignment at school where I have to contribute to a large open-source project. I will focus on number formatting, as suggested. Could I be assigned, please?

@dalexeev
Copy link
Member

With Godot 4.4 not only the indents get changed, but also all number values get a ".0" if they were integer.

I will focus on number formatting, as suggested.

In my opinion this doesn't need fixing. The JSON spec does not distinguish between int and float, so both 1 and 1.0 are correct. But the trailing .0 makes things more obvious. We deliberately included this change in 4.4, see #47502 for details.

When saving JSON in 4.4 the stringification result changed, this is expected. I think the only debate here is whether the editor should automatically save and therefore reformat all *.json files, even if the user has not re-saved them. Note that if you change a JSON resource in the inspector and save it, it will be reformatted anyway.

Could I be assigned, please?

You can start work without being assigned, we rarely use this GitHub feature. Sometimes priority issues are assigned to maintainers and active contributors, but it would be hard for us to track the progress on thousands of issues from hundreds of volunteer contributors.

If you have trouble choosing an issue, you can look at the good first issue label, an issue triage project for the area of ​​the engine you are interested in, or ask in the contributors chat. Good luck!

@luksteph
Copy link

luksteph commented Apr 10, 2025

I think the only debate here is whether the editor should automatically save and therefore reformat all *.json files

Could this be a user-selected setting maybe? Perhaps under Project Settings -> General -> FileSystem -> Import ?

@ratkingsminion
Copy link
Author

ratkingsminion commented Apr 10, 2025

I am all for an option to disable JSON resaving AND for an option to disable reformatting. My question still would be, why reformatting at all? What's the benefit?

@Calinou
Copy link
Member

Calinou commented Apr 10, 2025

I find it surprising that Godot has to overwrite the JSON for any reason in the first place. This will cause plenty of file locking issues on Windows. Due to this, Godot should not be rewriting source files. If it has to perform any rewriting, it should be strictly contained to .godot/. This is why the import system exists 🙂

I guess what's happening here is that json is part of the TextFile extensions, so if you open the JSON in the script editor and run the scene, the usual indentation or trailing whitespace changes configured in the Editor Settings will apply. That part is intended. If you don't want this to happen, disable Save Before Running in the Editor Settings.

@duongxinh2003
Copy link

Is there a way to handle the issue where my ID fields, which are currently of type int/long, are being converted to float and causing all HTTP calls to the server using that ID to fail? For example, my server response looks like: {"id": 1234}, but when it's passed through Godot, it becomes 'id' = 1234.0, and if I send this ID back to the server, it results in a conversion error.

@Zireael07
Copy link
Contributor

@duongxinh2003 That's a separate issue and that's because JSON doesn't work the way you think it does. It doesn't have integers

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

Successfully merging a pull request may close this issue.

7 participants