gbowne1 / json-maestro

JSONMaestro is a powerful tool designed for cleaning and processing JSON-like files. It simplifies tasks such as removing comments, eliminating duplicate keys, adding schema keys, and sorting keys. Ideal for developers working with configuration files and API responses, JSONMaestro enhances data integrity and prepares JSON data for further analysis
MIT License
2 stars 2 forks source link

[Bug] Issue with json being treated as jsonc with incorrect extension #31

Open gbowne1 opened 5 days ago

gbowne1 commented 5 days ago

At least in VSCode, unless its a VSCode configuration file such as settings.json, extensions.json, tasks.json, keybindings.json, launch.json file, any .json file with comments in it that does not have the extension .jsonc, VSCode will show linting and intellisense errors that says 'Comments are not permitted in JSON'. Rename the JSON file with comments in it to .jsonc and it will not complain about this.

We should be certain that in this case any generated, validated, etc JSON with comments gets the correct extension.

I don't know if other editors and IDE's treat json with comments this way or warn about it.

shoshta73 commented 5 days ago

I know what treesitter will complain about syntax, And Intellij Suite will also complain in certain situations

shoshta73 commented 5 days ago

Took a look with debbuger tru treesitters parser, when parsing json file with jsonc parser it expects compressed json and not json with comments

gbowne1 commented 5 days ago

ah, That makes sense. The warnings about comments in a .json file went away after I changed the extension to .jsonc in VSCode.

shoshta73 commented 4 days ago

Today i have check the AST of treesetter. My conclusion is that JSON with comment is not valid JSON but a valid JSON5

gbowne1 commented 4 days ago

very interesting. then how exactly does json allow comments, with or without .jsonc extension?

shoshta73 commented 4 days ago

As far as i have gone tru this standard it does not. Its configured per LSP implentation how it treats them. Also on the other hand jsonc can be interperted differently as per context.

As far i know some game servers / server-sdks implement handling of "Content-Type: application/jsonc" as compressed file usually done with lz compression per URL/Base64 encoding.

And also only filextension i have managed to file information that it supports is .jsonc everything else is done at LSP level. So there is apparend mix and mash of standards in open world.

gbowne1 commented 4 days ago

Ah, ok, so its more down to basically LSP and "intellisense" if you will.

as long as its inside the .vscode directory, the vscode configuration files with comments, its treats as normal JSON and ignores the warning.

package.json (used by npm/nodejs) doesn't seem to allow comments, and I haven't seen any with comments.

shoshta73 commented 2 days ago

package.json (used by npm/nodejs) doesn't seem to allow comments, and I haven't seen any with comments.

Yes, those are following JSON spec, basically anything that JSON.parse and JSON.stringify can convert to and from string is following JSON spec and at the same time javascripts spec for object notation

gbowne1 commented 2 days ago

yeah and that makes sense too.