XMLDevCon
🔒 100% Client-Side
⚡ XMLDevCon

JSON & XML

JSON Viewer & FormatterXML Formatter & ValidatorXML ↔ JSON Converter

Converters

XML ↔ JSON ConverterBase64 to File ConverterJSON/XML to TS

Formatters

XML FormatterJSON Viewer

Dev Tools

TypeScript GeneratorBase64 Encoder/DecoderBase64 to File Converter

Security

Secure JWT DecoderBase64 Decoder

🔒 100% Client-Side & Offline Ready

Tool

📋 JSON Formatter & Tree Viewer

Beautify or minify JSON, switch between text and an interactive collapsible tree view. Great for debugging API responses.

INPUT JSON0 chars
FORMATTED JSON

JSON Formatter — Developer Guide

Formatting and Inspecting JSON Payloads

JSON (JavaScript Object Notation) is the lightweight data-interchange standard of the web. While its syntax is simple, large JSON strings are often minified for transport, making them completely unreadable for developers. This tool allows you to beautify minified JSON, minify formatted JSON, and explore complex objects dynamically.

Step-by-Step Guide

  1. Input JSON — Paste your JSON string into the left input editor.
  2. Beautify or Minify — Click Beautify to format with spaces, or Minify to strip whitespace.
  3. Inspect Output — Select the Tree View mode on the right to inspect nested objects and arrays using a collapsible tree view.
  4. Copy Output — Copy or download your formatted result.

Interactive Tree Inspection

Our interactive tree viewer allows you to inspect complex JSON payloads:

  • Collapsible Nodes — Click any object {} or array [] prefix to collapse or expand its content.
  • Type Color Coding — Values are color-coded to identify data types immediately:
    • Strings appear in green.
    • Numbers appear in blue.
    • Booleans appear in purple.
    • Null values appear in red.

Code Snippets

Validate and Format JSON in Vanilla JavaScript

function formatJson(jsonString, spaces = 2) {
  try {
    const parsed = JSON.parse(jsonString);
    return {
      valid: true,
      formatted: JSON.stringify(parsed, null, spaces),
      error: null
    };
  } catch (err) {
    return {
      valid: false,
      formatted: null,
      error: err.message
    };
  }
}

// Example usage
const result = formatJson('{"name":"Bob","age":30}');
if (result.valid) {
  console.log(result.formatted);
} else {
  console.error("Invalid JSON:", result.error);
}

Common JSON Validation Mistakes

JSON syntax is much stricter than standard JavaScript object literals:

  • No Trailing Commas — Trailing commas at the end of lists (e.g., [1, 2,]) will crash standard parsers.
  • Double Quotes Only — Property keys and string values must use double quotes: {"key": "value"}. Single quotes ({'key': 'value'}) are invalid.
  • No Comments — JSON does not support inline comments (// or /* */).
  • No Special Types — Values like undefined or raw function declarations are invalid. Use null for empty states.
  • Unescaped Quotes — Quotes inside a string must be properly escaped (e.g., "He said \"hello\"").

Understanding these strict parsing rules is essential when debugging REST APIs and configurations.

Frequently Asked Questions

Beautify adds indentation and newlines to make JSON human-readable. Minify removes all whitespace for the most compact output — ideal for API payloads.
The Tree View parses your JSON and renders it as a collapsible hierarchy. Click any object {} or array [] node to expand or collapse it.
Top causes: trailing commas after the last item, single-quoted strings (JSON requires double quotes), missing quotes around keys, and using 'undefined' instead of 'null'.
The output panel is intentionally read-only. Edit in the left input panel and click Beautify to reformat.