How to apply javascript formatting to .json files?

Jader Dias picture Jader Dias · Sep 24, 2011 · Viewed 20.1k times · Source

The Ctrl + Shift + F hotkey in Eclipse can format a file. It doesn't work for .json files. How to make it work?

Answer

OldWolf picture OldWolf · Sep 24, 2011

You'll want to get the JSON Editor plugin if you don't already have it. You can find it here

The JSON Editor is a simple plugin for the Eclipse IDE that provides: - Color text highlighting - An Outline Tree view - JSON validation - Text formatting - Text folding for the JSON data format.

If the hot keys still don't work. Take a look under the menu as shown in the picture from their site here

Also, I see that there has been at least one issue with what looks to be the current versions formatting feature in the past. From their discussion site:

rlespinola 
2010-07-15 00:18:05 UTC
Using version 0.9.4, I do not see the option to "Format Text". Also, when I open a .json file, the outline view says "An outline is not available".

jdschulteis
2010-12-27 16:59:24 UTC
Using 0.9.4 on Helios, I also had "An outline is not available". I went to Window->Preferences->General->Editors->File Associations, selected '*.json' in the 'File types:' list, selected 'Json Editor' in the 'Associated editors:' list, and clicked 'Default'. I now get an outline, though it can be somewhat slow (6K line file).

Edit:

There are several ways to add a plugin. Eclipse recommends using the update manager. Try help > software updates > find and install

You can look here for some alternative methods.