Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to apply javascript formatting to .json files?

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

like image 434
Jader Dias Avatar asked Sep 24 '11 14:09

Jader Dias


People also ask

Can you put JavaScript in JSON?

The JSON Format Evaluates to JavaScript Objects The JSON format is syntactically identical to the code for creating JavaScript objects. Because of this similarity, a JavaScript program can easily convert JSON data into native JavaScript objects.

How do I format a JSON file?

Formatting# You can format your JSON document using Ctrl+Shift+I or Format Document from the context menu.


1 Answers

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.

like image 103
OldWolf Avatar answered Oct 16 '22 15:10

OldWolf