📋">

JSON Formatter

Validate & Format JSON Data • 2026 Edition

JSON Syntax Rules:

Show the formatter

\( \text{Valid JSON: } \{ "key": "value", "array": [1, 2, 3], "nested": \{ "prop": true \} \} \)

Where:

  • \( \text{Objects:} \) Enclosed in curly braces \{ \}
  • \( \text{Arrays:} \) Enclosed in square brackets [ ]
  • \( \text{Strings:} \) Enclosed in double quotes ""
  • \( \text{Values:} \) String, number, boolean, object, array, or null

JSON (JavaScript Object Notation) is a lightweight data interchange format that is easy for humans to read and write and easy for machines to parse and generate. It is based on a subset of JavaScript programming language and uses key-value pairs to represent data. JSON is widely used for APIs and configuration files.

Example: Valid JSON structure:

\(\{ \)

\("name": "John Doe",\)

\("age": 35,\)

\("active": true,\)

\("hobbies": ["reading", "gaming", "coding"]\)

\(\} \)

Thus, this structure is valid JSON that can be parsed by any JSON-compatible system.

Input JSON

Advanced Options

Formatted Output

✅ Valid JSON
Validation Status
1
Objects
1
Arrays
208
Characters
Metric Count Description
Objects 2 Curly brace {} structures
Arrays 1 Square bracket [] structures
Strings 7 Text values in quotes
Numbers 1 Numeric values
Booleans 1 true/false values
Null Values 0 null values
Keys 6 Object property names
Total Characters 208 Length of formatted JSON

Comprehensive JSON Guide

What is JSON?

JSON (JavaScript Object Notation) is a lightweight, text-based data interchange format that is easy for humans to read and write and easy for machines to parse and generate. It is language-independent but uses conventions familiar to programmers of the C-family of languages, including C, C++, C#, Java, JavaScript, Perl, Python, and many others.

JSON Syntax Rules

JSON has strict syntax rules that must be followed:

Data Structure: Objects contain key-value pairs
Key Format: Keys must be strings enclosed in double quotes
Value Types: String, Number, Boolean, Object, Array, or null
Array Format: Values separated by commas, enclosed in brackets

Where:

  • Objects: \{ "key": "value", "another": 123 \}
  • Arrays: [ "item1", "item2", 3, true, null ]
  • Strings: Must be enclosed in double quotes
  • Numbers: Can be integers or floating-point values
  • Booleans: true or false values
  • Null: Represents empty or undefined value

JSON Data Types
1
String: Text values enclosed in double quotes. Examples: "hello", "2023-01-01", "true". Strings can contain escape sequences like \n for newlines.
2
Number: Numeric values without quotes. Can be integers (42) or floating-point (3.14159). Exponents are allowed (1e10).
3
Boolean: Logical values true or false without quotes. Used for binary states and conditional data.
4
Array: Ordered list of values enclosed in square brackets. Values can be of any type and mixed types are allowed.
5
Object: Collection of key-value pairs enclosed in curly braces. Keys must be strings, values can be any type.
6
Null: Represents intentional absence of any object value. Written as the literal null without quotes.
Common JSON Patterns

JSON structures commonly follow these patterns:

  • Configuration Files: Key-value settings with nested objects
  • API Responses: Data wrapped in objects with metadata
  • Database Records: Flat or nested object structures
  • Message Formats: Structured communication between systems
JSON Best Practices
  • Consistent Naming: Use camelCase or snake_case consistently
  • Proper Nesting: Maintain clear hierarchical structure
  • Appropriate Types: Use correct data types for values
  • Validation: Always validate JSON before processing
  • Documentation: Include comments in surrounding code

JSON Formatting Learning Quiz

Question 1: Multiple Choice - JSON Syntax

Which of the following is a valid JSON string?

Solution:

The answer is B) "Hello World". In JSON, strings must be enclosed in double quotes. Single quotes (''), backticks (`), and unquoted text are not valid JSON string formats. This is a fundamental rule of JSON syntax that must be followed for valid JSON.

Pedagogical Explanation:

This question highlights one of the most basic but critical JSON syntax rules. Many developers coming from other languages assume single quotes work in JSON, but they don't. The double quote requirement is strict and any deviation results in invalid JSON. This rule exists to ensure unambiguous parsing across all platforms and languages.

Key Definitions:

JSON String: Text enclosed in double quotes

Double Quote: " character required for strings

Syntax Validation: Checking for proper JSON formatting

Important Rules:

• Strings must use double quotes

• Single quotes are invalid in JSON

• Backticks are invalid in JSON

Tips & Tricks:

• Always use double quotes for strings

• Remember: 'value' is invalid, "value" is valid

• Use a JSON validator to check syntax

Common Mistakes:

• Using single quotes instead of double quotes

• Forgetting quotes around string values

• Using backticks for strings

Question 2: Short Answer - JSON Validation

Why is the following JSON invalid? { name: "John", age: 30 }

Solution:

This JSON is invalid because the key "name" is not enclosed in double quotes. In JSON, all keys must be strings and therefore must be enclosed in double quotes. The correct format would be: { "name": "John", "age": 30 }. The same applies to the key "age" - it must also be quoted as "age".

Pedagogical Explanation:

This is a very common mistake, especially for developers familiar with JavaScript object literals. In JavaScript, you can omit quotes around keys if they're valid identifiers, but in JSON, all keys must be quoted strings. This ensures consistent parsing across all languages and platforms that support JSON.

Key Definitions:

JSON Key: Property name in key-value pair

Quoted Key: Key surrounded by double quotes

Identifier: Valid name in programming languages

Important Rules:

• All keys must be quoted strings

• JavaScript objects != JSON

• Strict syntax requirements

Tips & Tricks:

• Remember: JSON is stricter than JavaScript

• Always quote your keys

• Use a formatter to verify validity

Common Mistakes:

• Confusing JavaScript objects with JSON

• Forgetting to quote keys

• Assuming similar syntax rules

Question 3: Word Problem - Nested Structure

Create a valid JSON structure for a person with name, age, address (with street, city, zip), and hobbies (array of strings). Show proper nesting.

Solution:

{

"name": "Alice Johnson",

"age": 28,

"address": {

"street": "456 Oak Ave",

"city": "Springfield",

"zip": "62701"

},

"hobbies": ["photography", "cooking", "hiking"]

}

This structure properly nests the address object within the person object and uses an array for the hobbies, following all JSON syntax rules.

Pedagogical Explanation:

This example demonstrates how JSON supports nested structures, which is one of its key strengths. Objects can contain other objects and arrays, allowing for complex data hierarchies. Each level of nesting must follow the same JSON rules: keys quoted, proper value types, and correct punctuation.

Key Definitions:

Nested Object: Object contained within another object

Complex Data: Hierarchical information structure

Proper Indentation: Clear formatting for readability

Important Rules:

• Maintain consistent indentation

• Properly close all brackets

• Follow syntax at every level

Tips & Tricks:

• Use consistent indentation for readability

• Validate at each level of nesting

• Use formatters for complex structures

Common Mistakes:

• Mismatched brackets or braces

• Forgetting commas between items

• Improper nesting structure

Question 4: Application-Based Problem - Data Transformation

A developer receives this JavaScript object and needs to convert it to valid JSON. What changes are required? const obj = { name: 'Bob', details: { age: 35, active: true }, tags: ['admin', 'user'] };

Solution:

The JavaScript object needs these changes to become valid JSON:

1. Quote all keys: name → "name", age → "age", etc.

2. Change single quotes to double quotes: 'Bob' → "Bob", 'admin' → "admin"

Resulting valid JSON:

{

"name": "Bob",

"details": {

"age": 35,

"active": true

},

"tags": ["admin", "user"]

}

Note that the boolean value 'true' and number '35' don't need changes as they're already valid JSON values.

Pedagogical Explanation:

This question illustrates the common confusion between JavaScript objects and JSON. While JavaScript objects can have unquoted keys and single-quoted strings, JSON requires quoted keys and double-quoted strings. The conversion process involves syntactic changes but preserves the data structure and values.

Key Definitions:

JavaScript Object: Language-specific data structure

JSON: Language-independent data format

Data Transformation: Converting between formats

Important Rules:

• JSON is a subset of JavaScript object notation

• More restrictive than JavaScript objects

• Requires double quotes for strings and keys

Tips & Tricks:

• Use JSON.stringify() in JavaScript to convert

• Remember: Valid JSON is always valid JS object

• But valid JS object isn't always valid JSON

Common Mistakes:

• Assuming JavaScript objects are valid JSON

• Forgetting to quote keys during conversion

• Not changing single quotes to double quotes

Question 5: Multiple Choice - JSON Data Types

Which of the following is NOT a valid JSON data type?

Solution:

The answer is C) Function. JSON only supports these data types: strings, numbers, booleans, objects, arrays, and null. Functions are not a valid JSON data type. This is because JSON is designed as a data interchange format, not a programming language, so executable code (like functions) is not permitted.

Pedagogical Explanation:

This question tests understanding of JSON's limited data type support. While JavaScript (the language that inspired JSON) supports functions, dates, undefined, and other types, JSON as a data format only supports a specific set of types. This limitation ensures that JSON can be reliably parsed and generated across all programming languages and platforms.

Key Definitions:

JSON Data Types: Limited set of supported values

Function: Executable code (not supported)

Data Interchange: Format for sharing data

Important Rules:

• Only 6 data types are valid in JSON

• No executable code allowed

• Strict type limitations for portability

Tips & Tricks:

• Remember the 6 valid types: string, number, boolean, object, array, null

• Functions, dates, and undefined are not valid

• Convert complex types before JSON serialization

Common Mistakes:

• Including functions in JSON

• Assuming all JavaScript types are valid

• Forgetting that dates must be strings

JSON Fundamentals

JSON Structure

Object: \{ "key": "value", "array": [1, 2, 3] \}

Array: [ "item1", "item2", \{ "nested": true \} ]

Valid JSON Patterns

Correct: \{ "name": "John", "age": 30 \}

Incorrect: \{ name: "John", age: 30 \} (unquoted keys)

Always validate JSON before processing.

Key Rules:
  • All keys must be quoted strings
  • Strings must use double quotes
  • Trailing commas are not allowed
  • Only 6 data types are supported

Advanced JSON Operations

Parsing & Stringifying

Parse: JSON.parse(string) → JavaScript object

Stringify: JSON.stringify(object) → JSON string

Validation Techniques
  1. Use JSON.parse() with try/catch
  2. Implement schema validation
  3. Use online validators
  4. Validate data types
  5. Check for circular references
Considerations:
  • Handle parsing errors gracefully
  • Consider performance for large datasets
  • Validate data before processing
  • Be aware of size limitations

FAQ

Q: What's the difference between JSON and JavaScript objects?

A: While JSON is based on JavaScript object syntax, there are important differences:

JSON Requirements:

  • All keys must be double-quoted strings
  • Only specific data types allowed (string, number, boolean, object, array, null)
  • No trailing commas allowed
  • No comments allowed
  • No functions or undefined values

JavaScript Objects:

  • Keys can be unquoted if they're valid identifiers
  • Support functions, dates, undefined, and other types
  • Allow trailing commas
  • Can include comments in code
  • Can have methods and computed properties

Essentially, JSON is a subset of JavaScript object notation designed for data interchange.

Q: How do I validate JSON programmatically?

A: Here are the most common approaches:

JavaScript Validation:

try {
  const parsed = JSON.parse(jsonString);
  console.log('Valid JSON:', parsed);
} catch (error) {
  console.error('Invalid JSON:', error.message);
}

Python Validation:

import json
try:
    parsed = json.loads(json_string)
    print("Valid JSON:", parsed)
except json.JSONDecodeError as e:
    print("Invalid JSON:", e)

Server-side Validation:

  • Use schema validation libraries (like JSON Schema)
  • Implement custom validation rules
  • Sanitize input before parsing
  • Handle large payloads efficiently

Always validate JSON before processing to prevent errors and security vulnerabilities.

About

Developer Tools Team
This tool was created
This calculator was created by our Developer Tools Team , may make errors. Consider checking important information. Updated: April 2026.