Sublime Text - JSON formatter shortcut
I'm using SublimeText2.
How to reindent Json
code with a shortcut?
I've already installed packageControl
and it works.
I already tried JsonReindent
package but it has not a shortcut by default and i don't know its command name.
I already have this command (from my previous sublimetext2 on another pc, where it works fine):
// JSON reindent
{ "keys": ["ctrl+shift+j", "ctrl+shift+j"], "command": "json_reindent" },
But here it doesn't work.
I have come across this issue too. I tried to figure it out by install jsFormat as follows:
- Open Package Controll panel command+shift+p (mac), install package.
- Install jsFormat.
Edit the shortcut for the jsformat:
-
Choose Key-Binding user, then edit
[ { "keys": [ "command+l" ], "command": "reindent" }, { "keys": [ "ctrl+shift+s" ], "command": "auto_save" }, { "keys": [ "ctrl+alt+f" ], "command": "js_format" } ]
So next time when you try to format json code, just use ctrl+alt+f.
That's all.
Hope this will help you.
Cheers
Install this packages via CMD + SHIFT + P > Install package > Search for Pretty JSON and install.
And then turn ugly json via CMD + CTRL + J (OSX) CTRL + ALT + J (Windows/Linux) in pretty JSON!
Source is on GitHub. Credit
For sublime 4 below work for me:
Install "Pretty JSON" sublime 4 by refer below:
https://packagecontrol.io/packages/Pretty%20JSON
now for shortcut :
Click on Sublime -> Preferences -> Key Bindings
Here add the below json part inside existing json and save the file
{ "keys": [ "ctrl+shift+j" ], "command": "pretty_json" }
Complete json will look like below:
[{
"keys": [
"command+l"
],
"command": "reindent"
},
{
"keys": [
"ctrl+shift+s"
],
"command": "auto_save"
},
{
"keys": [
"ctrl+shift+k"
],
"command": "js_format"
},
{
"keys": [
"ctrl+shift+j"
],
"command": "pretty_json"
}
]