K
ken
HomeArticles🕐 Time Converter📋 JSON Tools🖼️ Base64 Image🔑 Password Generator Cron Expression🔤 Case Converter📱 QR Code#️⃣ Hash🔡 Encoding🔍 Regex Tester⚙️ Config Convert🔐 Encrypt/Decrypt⚖️ BMI Calculator🎲 Random Data🗜️ Image Tools🌍 World Clock🏛️ Roman Numeral🔢 Number to Chinese💰 Loan Calculator

JSON Tools

JSON (JavaScript Object Notation) is the backbone of data exchange on the web — lightweight, human-readable, and cross-language. It's the de facto standard for REST APIs, configuration files, and NoSQL documents. Whether you're debugging an API response, defining data contracts between frontend and backend, or editing VS Code settings, you work with JSON constantly. This tool bundles formatting, compression, validation, tree view, code generation, and sample data — six functions in one place for your JSON workflow.

Generate type definitions (structs/interfaces) for Go, TypeScript, Rust, Python, Java, Kotlin, Swift, and more — or reverse-generate sample JSON from Go structs and TypeScript interfaces. All processing happens locally in your browser; your JSON data is never uploaded anywhere.

JSON Input
📋

Enter JSON on the left to get started

📖 JSON Tools Guide

What Is JSON?

JSON (JavaScript Object Notation) is a lightweight, text-based data interchange format created by Douglas Crockford in 2001. It is based on JavaScript object syntax but is language-independent — virtually every programming language has a JSON parser. JSON supports six data types: strings, numbers, booleans, null, arrays, and objects. Its simplicity and cross-language compatibility have made it the universal standard for web APIs, replacing XML in nearly all modern use cases.

Six Core Functions

  • Format: Beautify minified JSON with tree indentation. Customize indent size (2/4/tab).
  • Compress: Strip all whitespace and newlines for the most compact representation — ideal for reducing network payload size.
  • Validate: Real-time JSON syntax checking with precise line/column error locations. Catches trailing commas, unquoted keys, single quotes, and comments.
  • Tree View: Interactive expand/collapse of JSON hierarchy — visually explore field relationships and nesting depth.
  • Struct Generation: Auto-generate type definitions for Go, TypeScript, Rust, Python, Java, Kotlin, Swift, C#, Dart, and Scala. Options include generic types, optional fields, and omitempty tags.
  • Sample JSON: Reverse operation — paste a Go struct or TypeScript interface to generate matching sample JSON. Perfect for quickly creating mock data from API type definitions.

How to Use

  1. Paste a JSON string or struct definition into the editor
  2. Toggle input mode: JSON or Struct Definition (Go/TypeScript)
  3. Switch output tabs: Format / Compress / Tree / Struct / Sample
  4. For struct generation: select target language, copy the generated types directly
  5. For sample JSON: paste a struct/interface and get mock JSON data instantly

Common Mistakes

  • Trailing comma: {"a": 1,} — JSON forbids commas after the last element. JavaScript and Python allow trailing commas, but JSON does not. Remove the final comma.
  • Unquoted keys: {name: "Alice"} — All keys in JSON must be double-quoted: {"name": "Alice"}. Single quotes also don't work.
  • Comments: JSON does not support /* */ or // comments. If you need comments, consider YAML or JSONC (VS Code's JSON with Comments variant).

Command-Line Alternatives

# Python format JSON echo '{"a":1,"b":2}' | python3 -m json.tool # jq — format and colorize echo '{"a":1,"b":2}' | jq . # jq — extract specific fields echo '{"users":[{"name":"Alice"},{"name":"Bob"}]}' | jq '.users[].name' # Node.js format JSON node -e "console.log(JSON.stringify(JSON.parse(process.argv[1]), null, 2))" '{"a":1}'

Frequently Asked Questions

What's the difference between JSON and a JavaScript object literal?
JSON is a cross-language data interchange format, while a JavaScript object literal is JS-specific. JSON has stricter syntax: keys must be double-quoted, JavaScript types like undefined/functions/Symbols are not allowed, and trailing commas are forbidden. JSON can be parsed by any language, object literals only work in JavaScript.
Does JSON support comments?
Standard JSON does not support comments. This is an intentional design choice by JSON's creator Douglas Crockford. Editors like VS Code support JSONC (JSON with Comments), but it's not part of the standard. For configurations that need comments, consider YAML.
How do I know if a string is valid JSON?
The most reliable way is to try JSON.parse() — if it throws an exception, it's invalid. Common issues include: unquoted keys, single quotes, trailing commas, and comments. This tool validates your input in real-time and highlights errors.
Can JSON numbers lose precision?
JSON itself doesn't limit number range, but JavaScript's Number type is a 64-bit double-precision float. Safe integer range is -2^53 to 2^53 (~9 quadrillion). Numbers beyond this lose precision. Solution: use string representation for large integers, e.g. "id": "9007199254740993".
What's the difference between JSON and XML?
Both are data interchange formats. JSON is more concise: no closing tags, faster parsing, smaller payload. XML supports attributes, namespaces, and Schema validation. Today, nearly all REST APIs use JSON, while SOAP and legacy systems still use XML.

Usage Examples

User Profile

A user profile showing strings, numbers, booleans, arrays, and nested objects.

{
  "name": "John Doe",
  "age": 28,
  "email": "john@example.com",
  "active": true,
  "tags": ["developer", "backend"],
  "address": {
    "city": "Beijing",
    "district": "Haidian",
    "zip": "100000"
  }
}

API Response

A paginated API response with data list and pagination info.

{
  "code": 200,
  "message": "success",
  "data": {
    "items": [
      { "id": 1, "title": "Article One", "views": 1234 },
      { "id": 2, "title": "Article Two", "views": 892 },
      { "id": 3, "title": "Article Three", "views": 567 }
    ],
    "pagination": {
      "page": 1,
      "pageSize": 10,
      "total": 56
    }
  }
}

Config File

An application configuration file with deeply nested JSON structure.

{
  "app": {
    "name": "MyApp",
    "version": "2.1.0",
    "debug": false
  },
  "database": {
    "host": "localhost",
    "port": 5432,
    "pool": {
      "min": 2,
      "max": 10
    }
  },
  "logging": {
    "level": "info",
    "format": "json"
  }
}

Related Tools