What does the JSON Formatter do?
The JSON Formatter & Beautifier parses, validates, and beautifies raw, minified, or unformatted JavaScript Object Notation (JSON) payloads into clean, human-readable data structures. Running entirely client-side on blueutils.com, this tool parses your data directly in your browser with zero network latency, absolute data privacy, and real-time syntax checking.
Whether debugging API responses, inspecting nested database dumps, auditing Kubernetes configs, or formatting JSON logs, this utility provides:
- Instant Client-Side Auto-Formatting: Formats input in real time as you type, paste, or upload files without requiring manual submit buttons.
- Configurable Indentation Modes: Standard 2-space indentation (industry default for web APIs), 4-space indentation, tab characters (
\t), or custom numeric spacing. - Syntax Error Localization: Detects RFC 8259 syntax violations and pinpoints the exact line number and column offset of syntax breaks (e.g. unquoted keys, trailing commas, or single quotes).
- Zero-Storage Privacy Guarantee: Processes 100% of data locally within your browser engine; no JSON payloads, API keys, or confidential customer records are transmitted to remote servers.
Core Concepts
Understanding the strict grammar and data types defined in RFC 8259 helps prevent formatting and parsing failures across distributed systems:
- RFC 8259 Specification Constraints:
- Double Quotes Only: All string literals and object keys must use standard double quotes (
"key": "value"). Single quotes ('key') and unquoted keys ({ key: 123 }) violate JSON grammar. - No Trailing Commas: Trailing commas after the final object key (
{"a": 1,}) or array element ([1, 2,]) cause strict JSON parsers to abort. - Literal Primitives: Boolean literals must be strictly lowercase (
true,false), and null values must benull. Capitalized variants (True,False,None,NULL) are invalid. - Numeric Formatting: Numbers must not contain leading zeros (
0123), hex notation (0xFF), or trailing decimal points (5.).
- Double Quotes Only: All string literals and object keys must use standard double quotes (
- Whitespace & AST Serialization:
- JSON is whitespace-agnostic. Minification strips tabs, newlines, and spaces to minimize HTTP payload bytes, while beautification recalculates the Abstract Syntax Tree (AST) to insert uniform indentation and line feeds for human maintainability.
- Character Encoding & Escape Sequences:
- Standard JSON uses UTF-8. Control characters (ASCII 0–31) and quotes must be escaped using backslashes (
\",\\,\n,\r,\t) or 4-digit hexadecimal unicode units (\uXXXX).
- Standard JSON uses UTF-8. Control characters (ASCII 0–31) and quotes must be escaped using backslashes (
How to use the tool?
- Load Raw JSON Input:
- Paste raw JSON text directly into the left editor (
Raw JSON Data), - Click Upload to load a local
.jsonor.txtfile, or - Click Sample to load a comprehensive JSON payload demonstrating objects, arrays, numbers, booleans, and nested nulls.
- Paste raw JSON text directly into the left editor (
- Select Indentation Spacing:
- 2 Spaces (Default): Compact, standard formatting optimized for web applications, microservices, and mobile API payloads.
- 4 Spaces: Wider visual hierarchy, ideal for deeply nested configuration files and technical documentation.
- Tab (
\t): Uses hardware tab stops, allowing individual developers to customize visual indent width in their own editors. - Custom: Enter any custom indent width between 1 and 10 spaces.
- Review & Export Output:
- The right editor (
Formatted JSON Result) updates automatically in real time with syntax highlighting and line numbers. - Click Copy to copy the formatted JSON directly to your clipboard.
- Click Download to save the formatted result as
output.jsonto your local machine. - If an error is present, the line gutter highlights the error line and displays the exact reason in the status banner below.
- The right editor (
Related Developer Utilities
- JSON Minifier & Compressor: Strip comments and whitespace to compress JSON payloads by up to 50% for fast network delivery.
- JSON Syntax Validator: Validate JSON syntax against RFC 8259 with exact line and column error diagnostics.
- JSON Diff Tool: Compare two JSON objects semantically and highlight added, modified, or removed keys.
- JSON to YAML Converter: Convert JSON structures into clean YAML for Kubernetes manifests and Docker Compose.
- JSON to TypeScript Converter: Generate TypeScript interfaces and types from sample JSON payloads.
REST API Integration
blueutils.com provides a free, high-performance REST API endpoint (POST https://blueutils.com/api/json/format) for programmatic JSON formatting, validation, and pretty-printing in backend scripts and build pipelines.
API Request Parameters
| Name | Type | Description | Example |
|---|---|---|---|
rawText / json |
String / Object | The JSON payload to format. Accepts either an escaped JSON string or a direct JSON object/array. | {"service": "auth", "port": 8080} |
indent |
Number / String | Indentation spacing (2, 4, "tab", or custom number 1–10). Defaults to 2. |
2 |
API Request Payload Examples
cURL (Using Direct JSON Object)
curl -X POST https://blueutils.com/api/json/format \
-H "Content-Type: application/json" \
-d '{
"json": {
"service": "auth",
"port": 8080,
"active": true
},
"indent": 2
}'cURL (Using Raw String)
curl -X POST https://blueutils.com/api/json/format \
-H "Content-Type: application/json" \
-d '{
"rawText": "{\"service\":\"auth\",\"port\":8080,\"active\":true}",
"indent": 2
}'Python
import requests
url = "https://blueutils.com/api/json/format"
# Pass either a Python dictionary or raw JSON string
payload = {
"json": {
"service": "auth",
"port": 8080,
"active": True
},
"indent": 2
}
headers = {"Content-Type": "application/json"}
response = requests.post(url, json=payload, headers=headers)
print(response.json())Java
import java.net.URI;
import java.net.http.HttpClient;
import java.net.http.HttpRequest;
import java.net.http.HttpResponse;
public class Main {
public static void main(String[] args) throws Exception {
String jsonPayload = """
{
"rawText": "{\\"service\\":\\"auth\\",\\"port\\":8080,\\"active\\":true}",
"indent": 2
}
""";
HttpClient client = HttpClient.newHttpClient();
HttpRequest request = HttpRequest.newBuilder()
.uri(URI.create("https://blueutils.com/api/json/format"))
.header("Content-Type", "application/json")
.POST(HttpRequest.BodyPublishers.ofString(jsonPayload))
.build();
HttpResponse<String> response = client.send(request, HttpResponse.BodyHandlers.ofString());
System.out.println(response.body());
}
}API Response Parameters
| Name | Type | Description | Example |
|---|---|---|---|
isValid |
Boolean | Indicates whether formatting and syntax validation succeeded. | true |
message |
String | Human-readable status description of the formatting operation. | "JSON formatted successfully." |
result |
String | The beautified, indented JSON output string. | "{\n \"service\": \"auth\"\n}" |
data |
Object / Array / Primitive | The parsed JSON object/array directly usable without an extra parsing step. | {"service": "auth", "port": 8080} |
originalSize |
Number | Byte size of the raw input payload (UTF-8). | 44 |
resultSize |
Number | Byte size of the formatted output string (UTF-8). | 54 |
nodeCount |
Number | Count of top-level properties or array items parsed. | 3 |
API Response Payload Examples
Success Response (HTTP 200 OK)
{
"isValid": true,
"message": "JSON formatted successfully.",
"result": "{\n \"service\": \"auth\",\n \"port\": 8080,\n \"active\": true\n}",
"data": {
"service": "auth",
"port": 8080,
"active": true
},
"originalSize": 44,
"resultSize": 54,
"nodeCount": 3
}Validation Failure Response (HTTP 400 Bad Request)
{
"isValid": false,
"error": "Invalid JSON syntax: Unexpected token '}' at line 3 column 1"
}Rate Limit Exceeded Response (HTTP 429 Too Many Requests)
{
"error": "API rate limit exceeded. Please wait or contact support@blueutils.com."
}Why use an API to format JSON?
Automating JSON formatting and validation via API offers several engineering benefits:
- CI/CD Build Pipeline Verification: Automatically validates that configuration files, localized JSON message bundles, and OpenAPI schemas are syntactically valid and deterministically formatted before deploying to production.
- Log Stream Normalization: Formats single-line minified JSON logs from microservices and Kubernetes containers into clean multi-line records for debugging dashboards.
- AI Agent & LLM Output Sanitization: LLMs frequently output malformed JSON containing subtle indentation flaws or missing quotes. Routing model responses through the API enforces strict RFC 8259 compliance without consuming extra generation tokens.
- Zero-Dependency Microservice Tooling: Small scripts and serverless functions can format payloads without bundling heavy parsing dependencies.
Native Usage
Format JSON locally using operating system command-line utilities, code editors, and native programming runtimes without third-party services:
Visual Studio Code & JetBrains Shortcuts
- VS Code (Windows / Linux):
Shift + Alt + F - VS Code (macOS):
Shift + Option + F - JetBrains IDEs (IntelliJ, WebStorm, PyCharm):
Ctrl + Alt + L(Windows/Linux) orCmd + Option + L(macOS) - Notepad++: Install the JSTool plugin and press
Ctrl + Alt + M
Windows (PowerShell)
Format raw JSON files natively using PowerShell's built-in ConvertFrom-Json and ConvertTo-Json cmdlets:
# Format raw JSON with 10 levels of nesting depth
Get-Content unformatted.json -Raw | ConvertFrom-Json | ConvertTo-Json -Depth 10 | Set-Content formatted.jsonLinux / Unix (Bash & jq)
Pretty-print JSON directly in your terminal using the industry-standard jq utility:
# Pretty-print JSON to output file
jq . unformatted.json > formatted.json
# Pretty-print directly to standard output
curl -s https://api.example.com/data | jq .Python
Format JSON using Python's standard library json module via command line or script:
# Terminal CLI one-liner
python -m json.tool unformatted.json formatted.jsonimport json
# Python script implementation
with open("unformatted.json", "r", encoding="utf-8") as infile:
data = json.load(infile)
with open("formatted.json", "w", encoding="utf-8") as outfile:
json.dump(data, outfile, indent=2, ensure_ascii=False)Java
Format JSON using standard Jackson ObjectMapper in Java 17+:
import com.fasterxml.jackson.databind.ObjectMapper;
import java.io.File;
public class JsonFormatter {
public static void main(String[] args) throws Exception {
ObjectMapper mapper = new ObjectMapper();
Object jsonObject = mapper.readValue(new File("unformatted.json"), Object.class);
String prettyJson = mapper.writerWithDefaultPrettyPrinter().writeValueAsString(jsonObject);
System.out.println(prettyJson);
}
}