Skip to content
Aarrange
0
Lines
0
Keys
0
Errors
Input
Tab types a tab. Press Escape, then Tab, to leave the editor.
Result
The result shows here as you type.Try , or .
On this page

About JSON Validator

Updated

JSON Validator checks your JSON as you type. When something is wrong, it rings the exact character, tells you the line and column, and says how to fix it in plain words. Paste or type your JSON in the editor, or press Validate.

The tool can also format JSON with your choice of indent, sort the keys, minify it to one line, and show its structure: the number of keys, the depth and the arrays. Lines that Format changed stay marked until you edit them, and Show before shows your text as it was. Press Example to try it with a sample.

To see what changed between two JSON files, use the Diff Checker. It compares the data, so key order and spaces do not count. To open your JSON in a spreadsheet, use the JSON to CSV Converter. To read the data as a tree or a table, use the JSON Viewer.

Not sure which tool to use? See the best JSON formatters compared.

Common JSON errors

Missing commas

Missing commas are the most common error in JSON. JSON data requires commas between each key-value pair. Missing or extra commas cause an error. A comma is required to separate key-value pairs, but not after the last pair in an object or array. For example, the following code is invalid:

Invalid
{
  "name": "John"
  "age": 30
}

The code above is fixed by adding a comma between the two key-value pairs:

Fixed
{
  "name": "John",
  "age": 30
}

Unescaped characters

Forgetting to escape characters in strings is another common error. JSON has a set of reserved characters that must be escaped with a backslash \: the double quote \" that delimits the string itself, and the backslash \ that escapes other characters. There are also control characters, such as \n for a new line, but these are overlooked less often. For example, the following code is invalid:

Invalid
{
  "accent": "Nina's accent is British.",
  "quote": "She said, "I'm from London.""
}

The code above is fixed by escaping the double quotes in the quote string:

Fixed
{
  "accent": "Nina's accent is British.",
  "quote": "She said, \"I'm from London.\""
}

Missing quotes

Missing quotes are another common error. Every key has to be enclosed in double quotes ", and so does every string value. For example, the following code is invalid:

Invalid
{
  name: "Anna",
  age: 27
}

The code above is fixed by adding double quotes around the keys:

Fixed
{
  "name": "Anna",
  "age": 27
}

Missing curly brackets

An object must be enclosed in curly brackets. For example, the following code is invalid:

Invalid
{
  "event": "Concert",
  "location":
    "city": "New York",
    "state": "NY"
}

The code above is fixed by adding curly brackets around the object:

Fixed
{
  "event": "Concert",
  "location": {
    "city": "New York",
    "state": "NY"
  }
}

JSON

JSON, an acronym for JavaScript Object Notation, is a compact and readable way to represent complex data structures. It allows smooth and robust data exchange between systems, which makes it very popular in web development and particularly useful for APIs. Its versatility and resemblance to human-readable text make it a widely adopted data format across many programming languages and platforms.

  • The conventional extension for a JSON file is .json. The operating system and applications use it to identify the file type and open the right program.
  • The MIME type for JSON is application/json. Browsers, applications and APIs use it to decide how to handle the data.

Despite its JavaScript origins, JSON is independent of any programming language. It can represent data that uses elements common to many programming languages, which makes it a universal data representation.

Other benefits of JSON

  • JSON is easy for people to read thanks to its neat formatting.
  • JSON is compact, as it does not rely on a heavy markup structure.
  • JSON is easy for programming languages to parse. In JavaScript it is identical to how you define a regular object.
  • There are JSON libraries for almost every programming language.

Proper JSON format

Understanding JSON does not demand proficiency in JavaScript, though such knowledge helps. Following these rules is essential:

  • Data is written as name/value pairs, "key": "value". The key is always in double quotes. The value is in double quotes if it is a string, like "prompt": "hello!", and without quotes if it is a number "age": 25, a boolean "isMarried": true, null "spouse": null, an object "address": { ... } or an array "children": ["John", "Jane"].
  • Name/value pairs are separated by commas, except after the last one: { "first": 1, "second": 2, "last": 3 }.
  • Objects are enclosed in curly brackets { ... }. An empty object is {}.
  • Arrays are enclosed in square brackets [ ... ]. An empty array is [].
  • Each key should be unique within an object on the same level.
  • Booleans are written true or false in lower case, and null is written null.
  • Numbers follow a double-precision floating-point format and avoid leading zeros.
  • Reserved characters in a string are escaped with a backslash \: the backslash itself, double quotes, and the control characters \n (new line), \r (carriage return), \t (tab), \b (backspace) and \f (form feed).
  • Unicode characters can be written with the \u escape sequence, for example "slogan": "Good enough™", where ™ is the trademark symbol ™.
  • Dates and similar types are written as strings, like "today": "2023-07-22", as JSON has no date type.

JSON in programming languages

JSON is supported by most programming languages. Here is how three of them convert data to JSON and back.

JavaScript
// monster.js
const monster = {
  name: 'Vecna',
  age: 1000,
  isAlive: true,
  hobbies: ['gorging on souls', 'collecting eyes'],
  address: { street: '123 The Upside Down', city: 'Hawkins', state: 'Indiana', country: 'USA' }
}

// JavaScript object to JSON
const monsterJSON = JSON.stringify(monster)

// JSON to JavaScript object
const monsterObject = JSON.parse(monsterJSON)

In JavaScript, the built-in JSON object converts an object to JSON with JSON.stringify() and back with JSON.parse().

Python
# monster.py
import json

monster = {
    "name": "Vecna",
    "age": 1000,
    "isAlive": True,
    "hobbies": ["gorging on souls", "collecting eyes"],
}

monster_json = json.dumps(monster)     # dictionary to JSON
monster_dict = json.loads(monster_json)  # JSON to dictionary

In Python, the json module converts a dictionary to JSON with json.dumps() and back with json.loads().

PHP
<?php
// monster.php
$monster = array(
    "name" => "Vecna",
    "age" => 1000,
    "isAlive" => true,
);

$monsterJSON = json_encode($monster);         // array to JSON
$monsterArray = json_decode($monsterJSON, true); // JSON to array

PHP uses the built-in functions json_encode() to convert an array to JSON and json_decode() to convert JSON back.

In short

JSON is a text-based, language-independent format for structured data. It is commonly used in APIs to exchange data between systems, and also for storage and configuration. JSON is a subset of JavaScript syntax, but it is not JavaScript.

Other JSON resources

JSON FAQ

What is JSON?

JSON is a data format that is used to represent structured data. It is a text-based format that is language independent. For a more detailed description, see the Wikipedia and W3Schools definitions of JSON.

What is JSON used for?

JSON is used to represent structured data. It is commonly used in APIs to exchange data between systems that use the same or different programming languages. It is also used for data storage and configuration files. Since JSON is a text-based format, it is excellent in situations where data needs to be language agnostic and easy to read.

How do you pronounce JSON?

JSON is most commonly pronounced Jay-sawn (phonetically: /ˈdʒeɪˌsɒn/), although in some practices and according to its founder, it is pronounced like the first name Jason (phonetically: /ˈdʒeɪsən/), which is shorter to say.

You can hear real people saying JSON on the American Pronunciation Guide YouTube video. To listen to the phonetics, paste the phonetic texts above into the IPA reader, and it reads them out loud. You can also watch the JSON founder explain how he thinks JSON should be pronounced on Honeypot originals on YouTube.

What is JSON syntax?

JSON syntax is the set of rules that define how JSON code should be written. JSON syntax is based on JavaScript syntax, but it is not JavaScript. JSON syntax is a subset of JavaScript syntax. It is defined in the JSON specification and described in detail with illustrated examples on the W3Schools page JSON Syntax.

What is JSON-LD and how is it different from JSON?

JSON-LD is a JSON-based format that is used to represent Linked Data as well as structured data, while JSON is used to represent only structured data. You can think of the LD part as a way to refer from one JSON document to another JSON document in another place or on another website.

JSON-LD follows the same rules as JSON, with some additional features. As such, it is a superset of JSON. To better understand JSON-LD, explore Schema.org and all the examples there, or read the JSON-LD definition in the JSON-LD specification.

What is the difference between JSON and XML?

JSON and XML are both used to represent structured data. XML uses tags to represent data, while JSON uses key-value pairs. JSON is more commonly used in APIs, while XML is more commonly used in configuration files.

W3Schools has a short but informative comparison, JSON vs XML, and AWS has a more detailed illustrated page, What is the difference between JSON and XML.

  • JSON is more compact than XML and considered by many to be easier to read.
  • JSON is more commonly used in APIs, while XML is more commonly used in configuration files.
  • JSON is more commonly used in JavaScript, while XML is more commonly used in Java.
What is the difference between JSON and YAML?

JSON and YAML are both used to represent structured data. YAML uses indentation to represent data, while JSON uses key-value pairs. As such the two formats are structured quite differently.

Builtin has a short text on the differences, JSON vs YAML, and AWS has a more detailed illustrated page, What is the difference between YAML and JSON.

  • JSON is more compact than YAML and considered by many to be easier to read.
  • JSON is more commonly used in APIs, while YAML is more commonly used in configuration files.
  • JSON is used in many languages and contexts, while YAML is most commonly used in Python.