How to format json for readable code reviews and prs
- Step 1Format JSON files before committing — Before git add, paste each modified JSON file and prettify it with the project's standard indent (2 or 4 spaces, consistent across the codebase). Copy the output back into the file.
- Step 2Sort keys for stable ordering — Enable key sorting so the same keys always appear in the same order regardless of how the file was generated. This prevents cosmetic key-order changes from appearing in diffs.
- Step 3Set a project-wide standard with Prettier — To enforce JSON formatting automatically, add Prettier to the project: npm install --save-dev prettier. Add a .prettierrc with jsonSingleQuote: false, tabWidth: 2. Run npx prettier --write '**/*.json' to format all files.
- Step 4Add a pre-commit hook — Use lint-staged with Prettier to format JSON automatically on git commit: npx husky init; echo 'npx lint-staged' > .husky/pre-commit. Configure lint-staged to run prettier --write on *.json files.
Frequently asked questions
How do I enforce consistent JSON formatting across a team?+
Configure Prettier in the project and add a .prettierrc file specifying tabWidth, useTabs, and other options. Add a pre-commit hook via husky and lint-staged that runs prettier --write on staged JSON files. The CI pipeline should also run prettier --check to fail builds with improperly formatted files.
Should I sort JSON keys in committed files?+
It depends on the file type. For machine-generated files (package.json, tsconfig.json), preserve key order — especially in package.json where key order has semantic meaning in some tools. For data files and test fixtures, sorted keys produce more stable diffs. Decide per file type and document it in the project's contributing guide.
Is the JSON content transmitted to JAD Apps?+
No. Formatting runs entirely in your browser. Test fixtures, seed data, and API mock files are never transmitted to JAD Apps servers.
Privacy first
Conversion runs locally in your browser. No file is uploaded — only metadata counters are saved for signed-in dashboard stats.