TR

Home / Guides / What Is JSON? Structure, Formatting, Validation and Finding Errors

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:

The values themselves can also be objects or arrays, so documents can nest as deeply as you like.

TypeExample
String"hello"
Number42 or 3.14
Booleantrue / false
Nullnull
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:

InputResultWhy
{"a":"x"}ValidDouble-quoted key and string
"hi"ValidA lone string is also a valid document
42ValidA lone number is also valid
nullValidNull value
[1,2,]InvalidTrailing comma
{"a":01}InvalidNumber with a leading zero
{"a":.5}InvalidA number must start with a digit: write 0.5
{"a":+1}InvalidA plus sign is not accepted
[1 2]InvalidNo 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

  1. Trailing comma: {"a": 1,} is invalid.
  2. Single quotes: Strings and keys require double quotes; 'a' is invalid.
  3. Unquoted key: {a: 1} is valid in JavaScript but invalid in JSON.
  4. Comments: JSON does not support comments.
  5. undefined, NaN and Infinity: They have no equivalent in JSON.
  6. Escape character error: A double quote inside a string must be written as \".

Traps with numbers, dates and null values

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?

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

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

  1. Paste the document into a formatter; note the line and column in the error message.
  2. Look at the character before that position: a missing or extra comma is usually right before it.
  3. Verify that quotes are double and balanced and that brackets match.
  4. Check that quotation marks and backslashes inside strings are written with escape characters.
  5. 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

This article is for general information only and is not legal, financial or medical advice. We are not an official institution.