IntelliJ reformat for JSON files stoped working.

已回答

Hello, previously I was able to format json file to make it look pretty and well-formatted but for some reason reformat (shortcut ⌘⌥L) for json files doesn't work anymore. Does anybody know what could be a reason for that?

0

Hi David,

Does formatting with the shortcut work for other file types?

Make sure *.json extension is not added to the formatter's 'Do not format' settings:

Also make sure there are no .editorconfig files in your project that could override IDE's formatting settings.

0

Arina Efremova I just checked and json is not in my 'Do not format' settings. It's weird I have 2 laptops and it's working fine on one of them and doesn't work on another. Is it possible to export some settings from one IntelliJ and import to another?

0

Yes, you can export/import the entire code style scheme from the same dialog.

Also, see if it helps to disable EditorConfig support.

0

I have this problem with IntelliJ IDEA 2023.2.5 (Ultimate Edition). The “Reformat code” used to work for .json files and suddenly it stopped working, even though I hadn't changed any settings.

The editor does complain about improperly formatted json, but doesn't allow to fix it - the “quick fixes” option is greyed out.

0

HB 
Is it possible to share the json file in question to try to reproduce on our end? You can upload it here: https://uploads.jetbrains.com, just provide the uploaded file ID.
Which scheme is selected for JSON code style - IDE (Default) or Project?



As some general troubleshooting steps you can try:

  • Temporarily disable all non-bundled plugins
  • If IDE scheme is selected - File > Manage IDE Settings > Restore Default Settings. Current settings will be automatically backed up, so they can be reverted later if needed.
  • If Project scheme is selected - close IDE, delete .idea folder and any *.iml files in your project root folder in file explorer, and re-import the project from existing sources. If you have a big project configuration (lots of run configurations etc.), it is worth backing up the .idea directory and .iml files before deleting them, just in case.
     
0

Hi, thanks for your answer! Unfortunately I can't share the json file (it contains actual production data) but this happens with any json file, it's not specific to any one file. I created a new json file with this content:

{
    "a": "…"
    "b": "fsfsf"
    "c": "sfafsafas"
}

and the editor does complain about the lack of commas, but “reformat code” or “reformat file” does nothing, and the “quick fixes" option is greyed out.

Which scheme is selected for JSON code style - IDE (Default) or Project?

IDE (Default). I tried changing it to Project, but it made no difference.

I've tried disabling all non-bundled plugins: it did not make a difference.

I restored default settings: it did not make a difference.

One thing I noticed was that when the json file is open, the editor says “no JSON schema”.

I tried selecting a couple of different schemas (Prettier, Eslint, TSLint, or IntelliJ Themes) and then clicking “reformat code” or “reformat file”, but nothing happened. Even after selecting a JSON schema, the quick fixes option is greyed out on the json errors that the editor complains about. Back when this worked, the quick fixes option would suggest fixes for problems that were not in compliance with the json standard.

0

Thank you for the update.
I could reproduce your issue, but as I can see, there are no intention actions (quick fixes) for JSON syntax errors. So it looks like it is system behavior. Have you seen this option – Quick Fixes in JSON syntax issues enabled before? 

On the other hand, reformatting a file doesn't affect the syntax errors. So it should still be possible to reformat JSON files, without fixing the syntax errors.

0

Ok, thanks for letting me know.

Have you seen this option – Quick Fixes in JSON syntax issues enabled before? 

Yes, this is how it used to work in IntelliJ until late November; the Quick Fixes suggested multiple options to either fix one error at a time or to fix all errors that didn't comply with the json standard - once I chose that, it automatically added commas where needed. Unfortunately I don't know if I had a specific JSON schema selected for that to work, but I don't think so - and I don't believe I touched any settings between it working and not working, one day it just worked and the next day it didn't.

0

Apologies for the delay.
I created an issue for this on our issue tracker: https://youtrack.jetbrains.com/issue/IDEA-341749. You can follow it for updates.
 

1

请先登录再写评论。