Format JSON Files in VS Code

Last Updated : 21 Oct, 2026

VS Code provides built-in tools to format JSON, improving readability and making nested objects and arrays easier to understand and debug.

  • Indentation: Organizes nested objects and arrays for easier reading.
  • Whitespace: Adds appropriate spacing and line breaks between JSON elements.
  • Consistency: Maintains uniform formatting throughout the file.

Format JSON Using the Built-in Formatter

VS Code includes a built-in JSON formatter, so you don't need to install an extension for basic formatting.

  • Open a JSON File: Open the JSON file in VS Code.
  • Open the Command Palette: Press Ctrl + Shift + P on Windows/Linux or Cmd + Shift + P on macOS.
  • Select Format Document: Search for Format Document and select the command.
  • View the Result: VS Code formats the JSON using the configured formatting settings.
Annotation-2024-07-12-005231

You can also use the keyboard shortcut:

  • Windows/Linux: Shift + Alt + F
  • macOS: Shift + Option + F

Example: Unformatted JSON

{"name":"John","age":30,"city":"New York","hobbies":["reading","traveling","swimming"],"education":{"highschool":"ABC High","college":"XYZ University"}}

Formatted JSON

{
  "name": "John",
  "age": 30,
  "city": "New York",
  "hobbies": [
    "reading",
    "traveling",
    "swimming"
  ],
  "education": {
    "highschool": "ABC High",
    "college": "XYZ University"
  }
}

Format JSON Using an Extension

You can install a JSON formatting extension if you need additional formatting options beyond the built-in formatter.

Search JSON Formatter Extension
Search JSON Formatter Extension
  • Open Extensions: Click the Extensions icon in the Activity Bar or press Ctrl + Shift + X on Windows/Linux or Cmd + Shift + X on macOS.
  • Search for an Extension: Enter JSON Formatter in the Extensions Marketplace.
  • Install the Extension: Choose an extension that meets your formatting requirements and click Install.
  • Format JSON: Use the formatting commands provided by the extension.

Note: For standard JSON formatting, the built-in formatter is generally sufficient. Extensions are useful when you need specialized formatting behavior or additional features.

Comment