Reputation: 90475
The Ctrl + Shift + F hotkey in Eclipse can format a file. It doesn't work for .json
files. How to make it work?
Upvotes: 17
Views: 20836
Reputation: 285
There are two options I figured out using Eclipse Luna (4.4.0).
Use a JSON Editor Plugin and define shortcuts
Use the Javascript Development Plugin with an ugly and anoying workaround
{"addressbook": {"name": "John Doe",
"address": {
"street": "5 Main Street", "city": "San Diego, CA", "zip": 91912
},
"phoneNumbers": [
"619 555-3452",
"664 555-4667"
]
}
}
var obj = {"addressbook": {"name": "John Doe",
"address": {
"street": "5 Main Street", "city": "San Diego, CA", "zip": 91912
},
"phoneNumbers": [
"619 555-3452",
"664 555-4667"
]
}
}
Upvotes: 5
Reputation: 23535
You could use the JavaScript editor that ships with Eclipse.
Upvotes: 4
Reputation: 346
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.
Upvotes: 16