Skip to main content

JSON Validator, Beautifier & Syntax Debugger

Rate this tool 0 of 0 ratings
Additional page content: Editable from the admin panel -> tools content.

Programmatic Code Snippets: Format & Pretty-Print JSON

How to implement Format & Pretty-Print JSON programmatically in Python, Node.js, PHP, and CLI
CLI & API Syntax
Format and indent JSON in Python
import json

raw_json = '{"name":"Toolbox24","active":true,"features":["beautifier","validator"]}'
parsed = json.loads(raw_json)
pretty_json = json.dumps(parsed, indent=2)
print(pretty_json)
Pretty-print JSON with 2 spaces in JavaScript / Node.js
const rawJson = '{"name":"Toolbox24","active":true,"features":["beautifier","validator"]}';
const parsed = JSON.parse(rawJson);
const prettyJson = JSON.stringify(parsed, null, 2);
console.log(prettyJson);
Format JSON with JSON_PRETTY_PRINT in PHP
<?php
$raw_json = '{"name":"Toolbox24","active":true,"features":["beautifier","validator"]}';
$parsed = json_decode($raw_json, true);
echo json_encode($parsed, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES);
Pretty-print JSON using jq or python on the CLI
# Using jq (recommended):
echo '{"name":"Toolbox24","active":true}' | jq .

# Using Python built-in json.tool:
echo '{"name":"Toolbox24","active":true}' | python3 -m json.tool
Embed
Need this Json Validator Beautifier calculator on your website, lab portal, or research blog?
Free HTML Widget 100% Responsive Zero Cookie Tracking
Notice a calculation discrepancy, rounding error, or glitch?
Help us maintain 100% scientific precision and report any issues directly to engineering.