logo
GeekFormat

JSON Formatter

No content yet

preview.json
Ready

Free online JSON Formatter tool. Supports JSON beautification, validation, minification, and JSON tree visual editing. Built-in syntax error detection and auto-repair. Supports code conversion to 13 programming languages (TypeScript/Java/Python/Go/Rust/Swift/Kotlin/C#/C++/PHP/MySQL/YAML/XML). Ideal for API debugging, configuration inspection, and log reading.

Related

Use Cases

  • Beautifying single-line JSON from API responses into a readable structure for easier troubleshooting
  • Formatting configuration files and log fields before further processing
  • Quickly validating whether JSON is legal and minifying size during development and debugging
  • Converting JSON to TypeScript interfaces, Java classes, Python dictionaries, or other code formats
  • Sorting by key names before comparing two API responses field by field
  • Mapping out complex nested structures from third-party APIs using tree view or mind map for quick hierarchy understanding
  • Expanding minified analytics logs and Webhook data for reading, to locate abnormal fields
  • Formatting compact JSON from local environment variables or configs for editing, then minifying to write back

Features

  • Intuitive JSON Beautification: Quickly organizes single-line data into an easy-to-read hierarchical structure, with switchable 2/4-space or Tab indentation
  • Validation & Minification Support: Real-time syntax error detection with precise location hints, one-click minification to the most compact single line
  • Code Conversion to 13 Programming Languages: One-click generation for TypeScript/Java/Python/Go/Rust/Swift/Kotlin/C#/C++/PHP/MySQL/YAML/XML
  • JSON Tree View Visual Editing: Collapse/expand nodes, intuitively view and modify deeply nested structures
  • Mind Map View: Presents object/array parent-child relationships via connected nodes, ideal for mapping complex structures
  • Key Sorting: Reorder object keys in ascending/descending alphabetical order, convenient for diff comparison and standardizing field order
  • Smooth Large File Handling: Virtual scrolling + Web Worker background parsing, several MB JSON files without lag
  • Privacy & Security: Entirely browser-local processing, zero data upload, safe for handling responses containing secrets
  • Convenient Operations: File upload/download, one-click copy, history undo, URL sharing — all included

How to Use

  1. Paste JSON content or upload a JSON file
  2. Select Beautify, Minify, or Validate mode; you can also switch to Tree View/Mind Map for visual browsing
  3. Review the formatted hierarchical structure and error messages; switch to Code Conversion if needed to generate target language structures
  4. Copy the processed content, download the file, or generate a shareable link

FAQ

How do I quickly format a single-line JSON into a readable structure?

Paste your JSON content into the editor to instantly beautify it. Great for viewing API responses, configuration files, and log fields. The tool automatically adds indentation and line breaks, organizing compact data into a clear hierarchical structure. It defaults to 2-space indentation; you can also switch indent size in the toolbar.

What's the difference between JSON Formatter and JSON Repair?

JSON Formatter is better suited for content that is already valid but hard to read. JSON Repair is better suited for fixing invalid structures like errors, missing quotes, and trailing commas. If formatting reports an error, we recommend doing JSON Repair first. In short: formatting only adjusts layout without changing content; repair attempts to fill in missing quotes/brackets and remove extra commas to make it valid JSON again.

Why does formatting JSON report an error?

Usually because the content isn't valid JSON — for example, it contains comments, single quotes, trailing commas, or unclosed brackets. The JSON specification (RFC 8259) requires keys to use double quotes, strings cannot use single quotes, there must be no comma after the last element, and // or /* */ comments are not allowed. In this case, it's better to do JSON Repair first, then format.

Is it suitable for API debugging and viewing log responses?

Absolutely. API responses, Webhook data, analytics logs, and config snippets often need formatting before troubleshooting. The tool also supports JSON tree view visual editing, mind map view, and code conversion to 13 programming languages, helping you quickly understand data structures.

Can I convert JSON to TypeScript interfaces or Java classes?

Yes. The tool supports converting JSON to TypeScript/Java/Python/Go/Rust/Swift/Kotlin/C#/C++/PHP/MySQL/YAML/XML — 13 formats in total. One-click generation of corresponding code structures, perfect for quickly generating frontend and backend data models from API responses.

Will formatted JSON data be uploaded to a server?

No. All formatting, validation, minification, and code conversion runs entirely locally in your browser. Data is never uploaded to any server. It's safe even when processing API responses containing secrets, tokens, or user privacy. Data is cleared when you close the page.

Can it handle large JSON files?

Yes. The tool uses virtual scrolling rendering and Web Worker background parsing. JSON files of several megabytes can be smoothly formatted and browsed without freezing the page. For very large files, we recommend uploading the JSON file directly rather than pasting, for more stable performance.

What is JSON Minify used for?

Minification removes all unnecessary spaces and line breaks from JSON, producing the most compact single-line result. This significantly reduces size, saves bandwidth and storage, and is commonly used for API transmission, writing configurations, embedding in code, or as environment variables. Minified JSON is semantically identical to formatted JSON; it's just not human-readable.

What are JSON Tree View and Mind Map View?

Tree View renders JSON as a collapsible hierarchical tree, supporting expand/collapse nodes and visual field editing, suitable for browsing deeply nested data. Mind Map View presents the structure as connected nodes, visually showing parent-child relationships between objects and arrays, suitable for mapping out complex data structures or giving presentations.

Can I sort by key names after formatting?

Yes. The tool provides a key sorting feature that supports rearranging object keys in ascending or descending alphabetical order, making it convenient for comparing differences between two JSONs, standardizing config file field ordering, or displaying API fields in a fixed order for Code Review.

Can I share formatted results with colleagues?

Yes. The tool supports compressing and encoding the current JSON content into a URL to generate a shareable link. Recipients can open the link to see the same data without uploading to a server, great for quick collaboration on API issue troubleshooting or reproducing data scenarios.

About JSON and JSON Formatting

JSON (JavaScript Object Notation) is a lightweight data interchange format that uses key-value pairs and arrays to represent data. Due to its simplicity, readability, and cross-language nature, it has become the de facto standard for Web APIs, configuration files, logs, and frontend-backend data transmission. JSON has only six basic value types: string, number, boolean, null, object, and array. Its syntax rules are jointly defined by RFC 8259 and ECMA-404.

JSON formatting (also called JSON beautification) is the process of adding proper indentation and line breaks to compact JSON without changing data content, organizing it into a hierarchical structure that is easy for humans to read. JSON in API responses, logs, and storage is often compressed into a single line, making it very difficult to read directly. After formatting, you can clearly see object nesting, array elements, and the value of each field.

The opposite operation to formatting is JSON minification, which removes all non-essential whitespace characters, converting JSON back to its most compact single-line form to reduce transmission size. Formatting and minification are a pair of reversible operations; neither changes JSON semantics, only affecting readability and size.

JSON validation checks whether a piece of text conforms to JSON syntax rules. Common invalid patterns include: using single quotes instead of double quotes, keys without quotes, trailing commas after the last element, containing // or /* */ comments, and incorrectly closed brackets or quotes. None of these are valid JSON, and formatting will report errors — in this case, you should use the JSON Repair tool first, then format.

Building on formatting, this tool also provides Tree View, Mind Map View, and code conversion to 13 programming languages: you can collapse JSON into a visual hierarchical tree to browse deep structures, or one-click convert API response JSON into TypeScript interfaces, Java classes, Python dictionaries, or database table creation statements for direct use in development. All processing is done locally in the browser; data is never uploaded to servers.

JSON Data Type Quick Reference

JSON has only six value types. Understanding them helps quickly determine whether data is valid and how to map to programming language types.

TypeExampleDescription
string"hello"String, must use double quotes, supports escape characters and \uXXXX Unicode encoding.
number25 / 3.14 / -1e5Number, supports integers, decimals, and scientific notation; parsed as double-precision float, no distinction between integer and float.
booleantrue / falseBoolean, can only be lowercase true or false.
nullnullNull value, representing no data; must be lowercase, different from empty string or 0.
object{"k": "v"}Object, a collection of key-value pairs wrapped in curly braces; keys must be double-quoted strings.
array[1, 2, 3]Array, an ordered list of values wrapped in square brackets; elements can be of different types.

JSON String Escape Character Table

The following characters in JSON strings must be escaped with a backslash; otherwise parsing will fail.

EscapeMeaning
\"Double quote
\\Backslash
\/Forward slash (optional escape)
\nNewline
\rCarriage return
\tTab
\bBackspace
\fForm feed
\uXXXXUnicode character represented by four hexadecimal digits

Common Invalid Patterns Reference

Below are commonly encountered invalid JSON patterns and their valid forms, for reference when formatting reports errors.

InvalidValidNote
{name: "a"}{"name": "a"}Keys must use double quotes
{'name': 'a'}{"name": "a"}Strings must use double quotes, not single quotes
{"a": 1,}{"a": 1}Trailing commas are not allowed
{"a": 1} // comment{"a": 1}JSON does not support comments
{"a": undefined}{"a": null}There is no undefined; use null for null values
{"a": .5}{"a": 0.5}Decimals must have an integer part 0

Code Examples

JavaScript: Format JSON using JSON.stringify

javascript

The third parameter of browser and Node.js built-in JSON.stringify specifies indentation, the most common programmatic way to format JSON.

const data = { name: '张三', age: 25, tags: ['a', 'b'] };

// Beautify: third parameter is indentation spaces (can also pass '\t' for Tab)
const pretty = JSON.stringify(data, null, 2);
console.log(pretty);

// Minify: omit the third parameter to get the most compact single line
const mini = JSON.stringify(data);
console.log(mini); // {"name":"张三","age":25,"tags":["a","b"]}

// Parse string to object (validates syntax, throws SyntaxError if invalid)
const obj = JSON.parse(pretty);

Python: Format using the json module

python

Python's standard library json uses indent and ensure_ascii parameters to control indentation and Chinese character display.

import json

data = {"name": "张三", "age": 25, "tags": ["a", "b"]}

# Beautified output, indent specifies indentation, ensure_ascii=False preserves Chinese
pretty = json.dumps(data, indent=2, ensure_ascii=False)
print(pretty)

# Minified output: use the most compact separators
mini = json.dumps(data, separators=(",", ":"), ensure_ascii=False)
print(mini)

# Parse string (throws json.JSONDecodeError if invalid)
obj = json.loads(pretty)

Command Line: Format JSON using jq

bash

jq is a powerful command-line tool for processing JSON, enabling quick beautification, minification, and field extraction.

# Beautify (default 2-space indent)
cat data.json | jq '.'

# Minify to single line
cat data.json | jq -c '.'

# Extract a specific field
cat data.json | jq '.user.name'

# Directly pipe curl results for beautification
curl -s https://api.example.com/user | jq '.'

Privacy & Security

All JSON formatting, validation, minification, and code conversion in this tool runs entirely locally in your browser. Data is never uploaded to any server, nor recorded or cached remotely. It is safe even when processing API responses containing secrets, tokens, or user information. Data is cleared when you close or refresh the page.

Authoritative References

Troubleshooting

Unexpected token ... in JSON (unexpected character / syntax error)

Most likely caused by single quotes, keys without double quotes, or containing // or /* */ comments. The JSON specification requires all strings and keys to use double quotes, and comments are not supported. Please switch to double quotes and remove comments, or use the JSON Repair tool first.

Unexpected end of JSON input (content ended unexpectedly)

Usually caused by incorrectly closed brackets {} or [] or quotes, resulting in incomplete JSON. Check that structures are properly paired and closed. When pasting API responses, you may have copied only partial content — ensure you copy completely.

Trailing comma causing errors

JSON does not allow commas after the last element of an object or array; for example {"a":1,} or [1,2,] are invalid. Remove the extra comma. JavaScript objects allow trailing commas, but JSON does not — be especially careful when copying from code.

Chinese or special characters displayed as \uXXXX

This is JSON's Unicode escape notation, which is inherently valid and can still be parsed normally after formatting. If you prefer to display Chinese directly, disable escaping on the generating side (e.g., Python's ensure_ascii=False, Go's disable HTML escaping).

Large number precision loss (e.g., ID becomes scientific notation or trailing zeros)

JSON numbers are parsed as IEEE 754 double-precision floats. Integers exceeding 2^53 (e.g., snowflake IDs, order numbers) lose precision. The solution is to wrap large integers as strings during transmission, i.e., "id": "9007199254740993", to avoid being parsed as numbers.

Want to convert formatted JSON back to a single line

Simply switch to "Minify" to convert beautified multi-line JSON back to the most compact single line for API transmission, writing configurations, or embedding in code. Minification and beautification are inverse operations and do not change data content.