Sublime Text - JSON formatter shortcut
JsonSublimetext3Sublimetext2IndentationSublime Text-PluginJson Problem Overview
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.
Json Solutions
Solution 1 - Json
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.
-
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
Solution 2 - Json
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!
Solution 3 - Json
For sublime 4 below work for me on MAC OS:
Install "Pretty JSON" sublime 4 by refer below:
- Use key combination Cmd + Shift + p and type Install Package
- Select Package Control: Install Package from the search results
- Type Pretty JSON and select it from the search results
OR use "Manual Installation" steps of below link
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" }
you can use cmd too instead of ctrl, set says as per your preference
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"
}
]
Now use below short key anytime to beautify json on sublime
ctrl+shift+j
You can also use command instead of ctrl
Solution 4 - Json
For Mac OS follow the steps:
Install Pretty JSON
- Use key combination
Cmd + Shift + p
and typeInstall Package
- Select
Package Control: Install Package
from the search results - Type
Pretty JSON
and select it from the search results
Add Key Binding
-
Open key bindings from
Sublime Text > Preferences > Key Bindings
-
Add following key short cut in key bindings
{ "keys": [ "command+shift+j" ], "command": "pretty_json" }
Use Pretty JSON
- Select JSON text and use key combination
Cmd + Shift + j
Solution 5 - Json
If you look at the source, the name of the sublime_plugin.TextCommand
subclass is SublimeJsonReindentCommand
. Per the conventions for command names, the resulting command is named sublime_json_reindent
. Simply change your key binding to:
{ "keys": ["ctrl+shift+j", "ctrl+shift+j"], "command": "sublime_json_reindent" },
and you should be all set.
Solution 6 - Json
You can use Command Palette
to format a text
//Call Command Palette
Ctrl+Shift+P
//Format code instead of CMD + CTRL + J (OSX)
pretty format
https://i.stack.imgur.com/bsuB8.png" height="150"/>
Solution 7 - Json
I am using Linux OS. I found the solution first installing the package controller then Pretty JSON package.
Solution 8 - Json
If you looking for how to install:(It may helpful someone who try to install as I was)
First enable package installer:
ctrl+shift+p
type “install package control” hit enter
It will place “Package Control. sublime-package” into ~/Library/Application Support/Sublime Text 3/Installed Packages.
Once it has done it will ask you too enter the package name, In that input box please type
pretty json and hit enter
Finally , you can format json by using ctrl+shift+p
Solution 9 - Json
Open the Command Palette: Press Ctrl+Shift+P (Windows) or Cmd+Shift+P (OS X). Type 'install' in the Command Palette input box, which should autocomplete to 'Install Package Control'.
Then go to Sublime Text -> Preferences -> Package Control -> Type Package Control: Install Package in the pop up box which would open a separate pop up box and in that type the package you want to install in this case "Pretty JSON"
Turn ugly json to pretty JSON via CMD + CTRL + J (OS X)
Solution 10 - Json
Since version 4 it is available under the Selection -> Format -> JSON menu option.