Skip to content

porada/prettier-plugin-expand-json

Repository files navigation

prettier-plugin-expand‑json

Expand JSON arrays and objects into multi‑line format with Prettier.

 

Overview

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.

Example

{
    "extends": "@standard-config/tsconfig",
    "compilerOptions": {
        "types": ["node", "vitest/globals"]
    }
}

…will always be formatted as:

{
    "extends": "@standard-config/tsconfig",
    "compilerOptions": {
        "types": [
            "node",
            "vitest/globals"
        ]
    }
}

Install

npm install --save-dev prettier-plugin-expand-json
pnpm add --save-dev prettier-plugin-expand-json

Usage

Reference 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"
                ]
            }
        }
    ]
}

Related

License

MIT © Dom Porada

About

Expand JSON arrays and objects into multi-line format with Prettier

Topics

Resources

License

Security policy

Stars

Watchers

Forks

Contributors