To format JSON in Sublime Text, first ensure the file's syntax is set to JSON via View → Syntax → JSON. 2. Use the built-in reindent command with Ctrl Alt B (Windows/Linux) or Cmd Ctrl B (Mac) to format the JSON. 3. For enhanced features like validation and sorting, install the Pretty JSON plugin via Package Control by opening the command palette, selecting Install Package, and searching for "Pretty JSON". 4. After installation, format JSON using Ctrl Alt J (Windows/Linux) or Ctrl Cmd J (Mac), or run "Pretty JSON: Format" from the command palette, which will also validate the JSON and alert on errors. 5. If formatting fails, manually fix indentation by selecting all text and using Edit → Line → Reindent, ensuring the syntax is correctly set to JSON. Proper syntax detection is essential for all methods to work correctly.
Formatting JSON in Sublime Text is simple once you know the right tools and steps. Here’s how to do it quickly and effectively.

Use the Built-in JSON Formatter
Sublime Text includes a built-in command to format JSON, but only when the file is set to JSON syntax.
- Open your JSON file in Sublime Text.
- Make sure the syntax is set to JSON:
- Click on the language name in the bottom-right corner (e.g., "Plain Text").
- Select Open Syntax Specific... → JavaScript → JSON.
- Or go to View → Syntax → JSON.
- With the file recognized as JSON, press:
- Ctrl Alt B (Windows/Linux)
- Cmd Ctrl B (Mac)
This runs the "Reindent" command, which properly formats the JSON structure.

?? Note: If the shortcut doesn’t work, it might be because the syntax isn’t correctly set to JSON. Double-check that.
Install Pretty JSON for Better Formatting
For more advanced formatting (like sorting keys or validating JSON), install the Pretty JSON plugin via Package Control.

Steps to install Pretty JSON:
- Install Package Control (if you haven’t already):
- Press Ctrl `` (backtick) to open the console.
- Paste the installation script from packagecontrol.io.
- Open the command palette:
- Ctrl Shift P (Windows/Linux) or Cmd Shift P (Mac)
- Type "Install Package", select Package Control: Install Package.
- Search for "Pretty JSON" and install it.
Use Pretty JSON to format:
- With your JSON file open, press:
- Ctrl Cmd J (Mac) or Ctrl Alt J (Windows/Linux)
- Or open the command palette and run "Pretty JSON: Format"
This will not only format but also validate your JSON. If there’s a syntax error, it will show an alert.
Fix Indentation Manually (Fallback)
If formatting doesn’t work:
- Select all text (Ctrl A or Cmd A).
- Go to Edit → Line → Reindent.
- Ensure the file is using JSON syntax — this step relies on it.
This method uses Sublime’s general reindent logic, which works decently for clean JSON.
Basically, the key is making sure Sublime recognizes your file as JSON. Once it does, formatting is just a shortcut away. For regular JSON work, Pretty JSON is worth installing — it adds validation, sorting, and better formatting options.
The above is the detailed content of How to format JSON in Sublime Text. For more information, please follow other related articles on the PHP Chinese website!

Hot AI Tools

Undress AI Tool
Undress images for free

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Performance optimization methods for converting PHP arrays to JSON include: using JSON extensions and the json_encode() function; adding the JSON_UNESCAPED_UNICODE option to avoid character escaping; using buffers to improve loop encoding performance; caching JSON encoding results; and considering using a third-party JSON encoding library.

JSON data can be saved into a MySQL database by using the gjson library or the json.Unmarshal function. The gjson library provides convenience methods to parse JSON fields, and the json.Unmarshal function requires a target type pointer to unmarshal JSON data. Both methods require preparing SQL statements and performing insert operations to persist the data into the database.

Annotations in the Jackson library control JSON serialization and deserialization: Serialization: @JsonIgnore: Ignore the property @JsonProperty: Specify the name @JsonGetter: Use the get method @JsonSetter: Use the set method Deserialization: @JsonIgnoreProperties: Ignore the property @ JsonProperty: Specify name @JsonCreator: Use constructor @JsonDeserialize: Custom logic

PHP provides the following functions to process JSON data: Parse JSON data: Use json_decode() to convert a JSON string into a PHP array. Create JSON data: Use json_encode() to convert a PHP array or object into a JSON string. Get specific values ??of JSON data: Use PHP array functions to access specific values, such as key-value pairs or array elements.

PHP arrays can be converted to JSON strings through the json_encode() function (for example: $json=json_encode($array);), and conversely, the json_decode() function can be used to convert from JSON to arrays ($array=json_decode($json);) . Other tips include avoiding deep conversions, specifying custom options, and using third-party libraries.

Parsing JSON data Parsing JSON data is a critical step in processing complex data. In Java, we can use the following methods: Use the Gson library: Gson is a widely used jsON parsing library that provides a concise and efficient api, as shown below: Gsongson=newGson();JsonObjectjsonObject=gson.fromJson(jsonString ,JsonObject.class); Using the Jackson library: Jackson is another popular JSON processing library that supports rich functionality and conversion to other formats (such as XML), as shown below: ObjectMappe

JSONFeed is a JSON-based RSS alternative that has its advantages simplicity and ease of use. 1) JSONFeed uses JSON format, which is easy to generate and parse. 2) It supports dynamic generation and is suitable for modern web development. 3) Using JSONFeed can improve content management efficiency and user experience.

RSS chose XML instead of JSON because: 1) XML's structure and verification capabilities are better than JSON, which is suitable for the needs of RSS complex data structures; 2) XML was supported extensively at that time; 3) Early versions of RSS were based on XML and have become a standard.
