Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 740
user2342558 Avatar asked Jan 20 '16 09:01

user2342558


People also ask

Can we format JSON in Sublime Text?

sublime-package” into ~/Library/Application Support/Sublime Text 3/Installed Packages. If you have this already, then just hit command+shift+p and type “package control: install package”, and then type “pretty” and select Pretty JSON. Then restart Sublime. Done!

How do I auto format a JSON file?

The key-map to auto-format the selected JSON is ALT-SHIFT-F. This is the same key-map to auto-format other languages too, so I often find myself doing CTRL-A (for select all text) followed by ALT-SHIFT-F to fix my messy C# code after a series of cut and paste operations.

How do I use pretty JSON?

Using Command Palette Ctrl+Shift+P find “Pretty JSON: Minify JSON” (you can search for part of it like 'json minify') this will make selection or full buffer as single line JSON which later you can use in command lines (curl/httpie) or somewhere else…


2 Answers

I have come across this issue too. I tried to figure it out by install jsFormat as follows:

  1. Open Package Controll panel command+shift+p (mac), install package.
  2. Install jsFormat.
  3. Edit the shortcut for the jsformat: sublime text preferences, package settings, jsFormat

  4. 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"   } ] 
  5. So next time when you try to format json code, just use ctrl+alt+f.

That's all.

Hope this will help you.

Cheers

like image 180
pigfly Avatar answered Sep 18 '22 18:09

pigfly


Install this packages via CMD + SHIFT + P > Install package > Search for Pretty JSON and install.

enter image description here

And then turn ugly json via CMD + CTRL + J (OSX) CTRL + ALT + J (Windows/Linux) in pretty JSON!

Source is on GitHub. Credit

like image 26
ArNo Avatar answered Sep 19 '22 18:09

ArNo