6

I want long JSON files to collapse in Sublime Text 3 like the Chrome network tab Preview section. Is there any Sublime Text package for this.

Something similar to following picture

Chrome Network Tab preview section

imPK
  • 764
  • 2
  • 7
  • 30

4 Answers4

15

Some of the answers here suggested Pretty JSON, but it didn't work for me. Although the installation was successful but still after pressing the shortcut key [command + control + j], it didn't work for me. I double-checked the setting, everything was correct. I was using Sublime version 3.2.2 and my macOS version was Catalina Version 10.15.3. I also found a thread in Github where multiple people mentioned the same issue with Sublime version 3.

enter image description here

Added a screenshot of my settings for reference.

Even though Pretty JSONdidn't work for me what worked for me was HTML-CSS-JS Prettify.

Following are the steps to install through Sublime Package Manager:
1. Cmd+Shift+P
2. type install, select Package Control: Install Package
3. type prettify, select HTML-CSS-JS Prettify

After installing it, for formatting the JSON text we need to use the shortcut key [command + shift + h]. That will format our JSON text.

Note: HTML-CSS-JS Prettify requires NodeJS in your system to work.

Hope this helps.

Rito
  • 3,092
  • 2
  • 27
  • 40
1

You can try Pretty JSON. It is the best I have found to prettify and validade JSON codes. But it won't give list indexes like chrome. At most you can fold those list itens folding by levels.

vassis
  • 173
  • 2
  • 9
  • Yes Pretty JSON doesn't work like chrome preview, and I already tried this before posting this question. Is there any other editor apart from sublime which serves this purpose – imPK Mar 04 '19 at 18:08
  • Doesn't show up in the package manager of Sublime Text 4. – André C. Andersen Jun 22 '21 at 10:49
1

We will use Pretty JSON package from package control in Sublime Text 3:

Installation

Install this sublime text 2/3 package via Package Control search for package: “Pretty JSON

Usage

To prettify JSON, make selection of json (or else it will try to use full view buffer) and press keys:

  • Linux: ctrl+alt+j
  • OS X: cmd+ctrl+j
  • Windows:ctrl+alt+j

or through Command Palette Ctrl+Shift+P find “Pretty JSON: Format (Pretty Print) JSON” (you can search for part of it like 'pretty format')

If selection is empty and configuration entry use_entire_file_if_no_selection is true, tries to prettify whole file

If JSON is not valid it will be displayed in status bar of Sublime Text

  • I already tried pretty JSON which didn't serve my purpose so posted this question – imPK Mar 04 '19 at 18:07
  • 1
    I am using Sublime version 3.2.2 and this is not working. Checked the setting also, everything is correct. – Rito May 13 '20 at 09:33
1

Had the same problem: Pretty JSON did not work for me (Ubuntu 16.04 LTS and ST 3.2.2). The alternative suggested by Rito, HTML-CSS-JS Prettify, requires NodeJS in your system to work.

Another alternative that does not require NodeJS which worked fine for me is the Pretty YAML ST-plugin which uses PyYAML internally.

Install is analogous to Rito's comment (and detailed on the github page).

Use Alt+Ctrl+Y to prettify a selection (or whole file)

porl
  • 11
  • 1