A Visual Studio Code extension that formats .json (and .jsonc) files four different ways, on the whole document or just the current selection.
| Mode |
Description |
| JSON: Pretty |
Fully indented — each object property and each array item on its own line. |
| JSON: Ugly / Minimize |
Compact, single line, no whitespace. |
| JSON: Newline After Each Item |
Array items are expanded onto their own lines; objects stay inline. |
| JSON: Newline After Each Property |
Object properties are expanded onto their own lines; arrays stay inline. |
| JSON: Validate Document |
Validate the JSON, document only. |
Each mode, except Validate has two variants:
- Format Document — reformats the entire file.
- Format Selection — reformats only the selected text (must be valid JSON on its own).
Usage
- Open a JSON file.
- Right-click in the editor and pick one of the YAJF commands, or
- Open the Command Palette (
Ctrl+Shift+P) and search for YAJF.
Selection commands appear in the right-click menu only when text is selected.
Indentation follows the editor's Insert Spaces / Tab Size settings.
Example
Input:
{"name":"test","tags":["a","b"],"info":{"x":1,"y":2}}
Pretty
{
"name": "test",
"tags": [
"a",
"b"
],
"info": {
"x": 1,
"y": 2
}
}
Ugly / Minimize
{"name":"test","tags":["a","b"],"info":{"x":1,"y":2}}
Newline After Each Item
{"name":"test","tags":[
"a",
"b"
],"info":{"x":1,"y":2}}
Newline After Each Property
{
"name": "test",
"tags": ["a","b"],
"info": {
"x": 1,
"y": 2
}
}
Requirements
VS Code ^1.85.0.
License
MIT