Expand JSON arrays and objects into multi‑line format with Prettier.
This plugin expands all JSON arrays and objects into a consistent multi-line format.
- Works with both JSON and JSONC files.
- Supports files that Prettier treats as special cases, including
package.json,composer.json, and others. - Comes without any additional dependencies.
{
"extends": "@standard-config/tsconfig",
"compilerOptions": {
"types": ["node", "vitest/globals"]
}
}…will always be formatted as:
{
"extends": "@standard-config/tsconfig",
"compilerOptions": {
"types": [
"node",
"vitest/globals"
]
}
}npm install --save-dev prettier-plugin-expand-jsonpnpm add --save-dev prettier-plugin-expand-jsonReference prettier-plugin-expand-json in your Prettier config:
{
"plugins": [
"prettier-plugin-expand-json"
]
}If you’re using any other JSON plugins, make sure prettier-plugin-expand-json is listed last. This applies to each overrides entry as well.
{
"plugins": [
"prettier-plugin-sort-json",
"prettier-plugin-expand-json"
]
}{
"overrides": [
{
"files": "**/package.json",
"options": {
"plugins": [
"prettier-plugin-pkg",
"prettier-plugin-expand-json"
]
}
}
]
}MIT © Dom Porada