What is JSON?
JSON (JavaScript Object Notation) is a lightweight data interchange format that has become the de facto standard for web APIs and configuration files. Created by Douglas Crockford in the early 2000s, JSON is language-independent but uses conventions familiar to programmers of the C family of languages.
JSON supports six data types: strings, numbers, booleans, null, arrays, and objects. Its simplicity and readability make it ideal for data exchange between servers and web applications.
How to Format JSON
- Paste your JSON data into the input area
- Choose your preferred indentation (2 spaces, 4 spaces, or tabs)
- Click the “Format” button or press
Ctrl+Enter - Copy the formatted result with the “Copy” button or
Ctrl+Shift+C
The formatter handles nested objects and arrays, properly escaping special characters and maintaining data integrity.
Common JSON Errors and How to Fix Them
- Trailing commas: JSON doesn’t allow trailing commas after the last element in an object or array. Remove the comma before
}or]. - Single quotes: JSON requires double quotes for strings. Replace
'value'with"value". - Unquoted keys: All object keys must be double-quoted strings. Change
{key: "value"}to{"key": "value"}. - Comments: JSON doesn’t support comments. Remove any
//or/* */comments. - Missing commas: Ensure each key-value pair is separated by a comma.
JSON vs XML
| Feature | JSON | XML |
|---|---|---|
| Readability | More concise | More verbose |
| Data types | Native support | All values are strings |
| Arrays | Built-in | Requires repeated elements |
| Parsing | JSON.parse() | DOM/SAX parsers |
| Size | Smaller | Larger due to tags |
| Comments | Not supported | Supported |
JSON is generally preferred for APIs due to its smaller size and native JavaScript support, while XML remains popular in enterprise systems and document-oriented applications.