What Is JSON? Structure, Formatting, Validation and Finding Errors
Updated: November 6, 2026 · AracMerkezi
▶ Open JSON Formatter / Minifier
JSON (JavaScript Object Notation) is a lightweight format used to store data as text and carry it between programs. Web APIs, configuration files and mobile apps use JSON almost everywhere. Its biggest advantages are that people can read it and that nearly every programming language supports it. This guide introduces JSON through its structure, shows how to read a value from inside a document, and offers a comparison table that answers “why is it invalid?” The results of the examples were verified by running them in Node.js.
The structure of JSON
A JSON document is made of two structures:
- Object:
"key": valuepairs inside curly braces. Example:{"ad": "Ayşe", "yas": 30} - Array: A list of values inside square brackets. Example:
[1, 2, 3]
The values themselves can also be objects or arrays, so documents can nest as deeply as you like.
| Type | Example |
|---|---|
| String | "hello" |
| Number | 42 or 3.14 |
| Boolean | true / false |
| Null | null |
| Object | {"a": 1} |
| Array | [1, 2] |
Example 1: Reading a nested document
Consider an order document: {"musteri":{"ad":"Ayşe","adres":{"sehir":"İzmir"}},"kalemler":[{"kod":"A1","adet":2},{"kod":"B7","adet":1}]}. It is one line and 108 characters long. Formatted with indentation it grows to 200 characters, about 85% longer, but becomes readable to the eye. Values inside are reached with dots and index numbers: the path musteri.adres.sehir gives İzmir for the city. The path kalemler[1].kod gives B7 for the code of the second item; because the index starts at 0, the second item is number 1. The most common beginner mistake is assuming the index starts at 1.
Example 2: Valid or invalid?
The inputs below were tried with JSON.parse:
| Input | Result | Why |
|---|---|---|
| {"a":"x"} | Valid | Double-quoted key and string |
| "hi" | Valid | A lone string is also a valid document |
| 42 | Valid | A lone number is also valid |
| null | Valid | Null value |
| [1,2,] | Invalid | Trailing comma |
| {"a":01} | Invalid | Number with a leading zero |
| {"a":.5} | Invalid | A number must start with a digit: write 0.5 |
| {"a":+1} | Invalid | A plus sign is not accepted |
| [1 2] | Invalid | No comma between the elements |
The wording of error messages differs from engine to engine; the line and column information in the message is usually enough to locate the problem.
The most common JSON mistakes
- Trailing comma:
{"a": 1,}is invalid. - Single quotes: Strings and keys require double quotes;
'a'is invalid. - Unquoted key:
{a: 1}is valid in JavaScript but invalid in JSON. - Comments: JSON does not support comments.
- undefined, NaN and Infinity: They have no equivalent in JSON.
- Escape character error: A double quote inside a string must be written as
\".
Traps with numbers, dates and null values
- Large numbers:
JSON.parse("12345678901234567890")gives 12345678901234567000 in JavaScript; integers larger than 2⁵³ lose precision. That is why carrying ID numbers as strings is safer. - Dates: JSON has no date type. Dates are usually written as ISO 8601 text:
"2026-11-05T00:00:00.000Z". - Missing values:
JSON.stringifydropsundefinedand function values and turnsNaNintonull. Data loss is silent. - Duplicate keys: JavaScript reads
{"a":1,"a":2}and keeps the last one (a= 2). This behavior is not strictly defined by the standard; avoid duplicate keys. - Turkish characters: Python's
json.dumpswritesAyşeas"Ay\u015fe"by default; if you passensure_ascii=Falsethe letter stays as is. Both are valid and represent the same data.
Example 3: The same data as JSON and as CSV
Consider a list of two people: [{"ad":"Ayşe","sehir":"İzmir"},{"ad":"Can","sehir":"Ankara"}]. This document is 61 characters. If the same data is written as CSV with the lines ad,sehir, Ayşe,İzmir, Can,Ankara, it takes about 30 characters, because the key names are not repeated on every row. On the other hand, CSV cannot carry nested structure, the difference between an empty value and an empty string, or data types. For flat, many-row, table-like data CSV is suitable; for nested data whose types must be preserved, JSON is suitable. When converting, remember that nested fields are turned into flattened columns such as adres.sehir.
When is JSON not suitable?
- In configuration files that need to contain comments and explanations. Formats that support comments, such as YAML, are more comfortable then.
- In very large data streams that must be processed line by line. A line-based layout that writes each line as a separate JSON document does not require loading the whole file into memory.
- When carrying binary data. Images and files get into JSON only through an encoding such as Base64, and the size grows by about one third.
- When integer precision is critical (very long IDs, monetary amounts). Carrying money amounts as integers in cents or as strings avoids floating-point surprises such as
0.1 + 0.2 = 0.30000000000000004.
Formatting and minifying
Formatting makes the document readable with indentation, while minifying removes whitespace to reduce file size. Formatted is preferred when debugging, minified when sending over the network. The JSON Formatter tool both formats and tells you whether the document is valid.
Converting to other formats
- To use it as a table: JSON ↔ CSV Converter. For details see the What is a CSV file guide.
- For configuration files: JSON → YAML Converter. You can find the differences in the YAML vs JSON guide.
- For type definitions in TypeScript projects: JSON → TypeScript Converter
- To compare with XML: XML vs JSON
Security note
Do not treat JSON coming from an API as executable code (for example, do not use eval); use the standard JSON.parse function. Do not paste JSON containing passwords or access keys into sites you do not know. The tools on this site process your data in your browser.
A short checklist for finding errors
- Paste the document into a formatter; note the line and column in the error message.
- Look at the character before that position: a missing or extra comma is usually right before it.
- Verify that quotes are double and balanced and that brackets match.
- Check that quotation marks and backslashes inside strings are written with escape characters.
- If there is still a problem, split the document in two and try half of it; the faulty part narrows down quickly. After finding the error, remember to validate the corrected document again and, if possible, fix the code that produced the error too; otherwise the same error will appear in the next piece of data.
Frequently asked questions
Can you write comments in JSON?
No, JSON does not support comments; adding a comment makes the document invalid.
Is JSON the same as a JavaScript object?
They are similar but not the same; in JSON keys and strings must be in double quotes and a trailing comma is invalid.
Can I convert JSON to CSV?
An array of objects can be converted into a table whose columns are the keys; nested structures need flattening.
Tools mentioned in this guide
More guides
- What Is YAML? Indentation Rules, Differences from JSON, and Common Mistakes – What is YAML, and how does indentation work? Differences between YAML and JSON, common mistakes (tabs, colons, yes/no), and converting YAML to JSON.
- What Is Fake Test Data? A Guide to Safe Mock Data for Testing and Demos – What is fake test data and why not use real customer data? Reserved example.com domains, edge-case records, pagination math, and JSON/CSV and UUID use.
- What Are JSON, Base64 and URL Encoding? Encoding vs Encryption vs Hashing – What do JSON, Base64, URL encoding, HTML entities, SHA and JWT do? Encoding vs encryption vs hashing, with examples that were run and verified.
- What Is Semver? MAJOR.MINOR.PATCH Version Numbers and ^ ~ Ranges – What is semantic versioning (semver)? MAJOR.MINOR.PATCH bump rules, pre-release ordering, ^ and ~ ranges and which version gets installed, with examples.
- What Is a CSV File? Delimiter and Turkish Character Problems, Converting CSV to JSON and SQL – What is a CSV file, and comma or semicolon? Turkish character problems, quoting rules, and converting CSV to JSON, Markdown, HTML, or SQL INSERT.
This article is for general information only and is not legal, financial or medical advice. We are not an official institution.