DevTools Hub

Guides › What Is JSON? Syntax Rules, Common Errors and Fixes, Formatting

What Is JSON? Syntax Rules, Common Errors and Fixes, Formatting

JSON (JavaScript Object Notation) is a lightweight text format for data. The name comes from JavaScript, but nearly every programming language supports it, and it is the most common format for web API responses, configuration files, IoT messages and logs. It is standardized as RFC 8259 and ECMA-404.

Structure and data types

{
  "device": "sensor-01",
  "online": true,
  "temperature": 23.5,
  "tags": ["line1", "zone-a"],
  "location": { "lat": 37.5665, "lng": 126.978 },
  "error": null
}
TypeExampleNotes
string"hello"Double quotes only
number42, -3.14, 1e-6No int/float distinction; no leading zeros (012 is invalid)
booleantrue, falseLowercase only
nullnullNo value; lowercase only
object{"key": value}Key/value pairs; keys are strings
array[1, 2, 3]Ordered list; mixed types allowed

Syntax rules (how JSON differs from JavaScript objects)

Common errors and fixes

InvalidCauseFix
{name: "kim"}Unquoted key{"name": "kim"}
{'name': 'kim'}Single quotesUse double quotes
{"a": 1, "b": 2,}Trailing commaRemove the last comma
{"a": 1 "b": 2}Missing commaAdd a comma between members
{"path": "C:\new"}Backslash read as an escape"C:\\new"
{"v": NaN}Not a JSON valuenull or a string
{"a": 1}}Unbalanced bracesCount opening and closing brackets

Reading error messages

This site's JSON validator highlights the error position as soon as you paste.

Formatting (beautify) and minifying

Whitespace in JSON has no meaning, so the same data can take two forms.

// formatted
{
  "id": 1,
  "ok": true
}
// minified
{"id":1,"ok":true}

In JavaScript use JSON.stringify(obj, null, 2) to format and JSON.stringify(obj) to minify. In Python, json.dumps(obj, indent=2, ensure_ascii=False) keeps non-ASCII text readable instead of \uXXXX escapes.

Pitfalls

JSON vs XML vs CSV

ItemJSONXMLCSV
StructureNested objects and arraysNested tags and attributesTable (rows and columns)
SizeSmallLarge (closing tags)Smallest
TypesString, number, boolean, nullAll text (types via schema)All text
Typical useWeb APIs, config, IoTDocuments, enterprise systems, SOAPSpreadsheets, analysis, logs

For format conversion and test data see the CSV, XML and test data guide.

Try it now: JSON Validator (runs in your browser, no data is sent anywhere)