jsonapijavascriptdevelopment

JSON: a complete guide to syntax and working with the format

What is JSON, its syntax, data types, common parsing errors and examples in JavaScript, Python and PHP.

Published February 23, 2026·Time to read: 8 min

What is JSON?

JSON (JavaScript Object Notation) is a text-based data exchange format. People read it and machines parse it. Used in REST API, config files, databases and everywhere.

JSON syntax

{ 
"name": "Ivan", 
"age": 30, 
"active": true, 
"score": 9.5, 
"tags": ["dev", "js", "api"], 
"address": { 
"city": "Moscow", 
"zip": "101000" 
}, 
"phone": null 
} 

Data types

TypeExample
------
String`"text"`
Number`42`, `3.14`
Boolean`true`, `false`
Null`null`
Array`[1, 2, 3]`
Object`{"key": "value"}`

5 common mistakes

// ❌ Comma at the end (trailing comma) 
{"name": "Ivan",} 

// ❌ Single quotes 
{'name': 'Ivan'} 

// ❌ Comments (not supported!) 
{"name": "Ivan" /* author */} 

// ❌ Keys without quotes 
{name: "Ivan"} 

// ❌ undefined (not a JSON type) 
{"value": undefined} 

Working with JSON in different languages

// JavaScript 
const obj = JSON.parse('{"name":"Ivan"}'); 
const str = JSON.stringify({ name: 'Ivan' }, null, 2); 

//Python 
import json 
obj = json.loads('{"name": "Ivan"}') 
str = json.dumps({"name": "Ivan"}, indent=2, ensure_ascii=False) 

//PHP 
$obj = json_decode('{"name":"Ivan"}', true); 
$str = json_encode(["name" => "Ivan"], JSON_PRETTY_PRINT | JSON_UNESCAPED_UNICODE); 

Format and validate your JSON - syntax highlighting, minification and error detection.

We use cookies for analytics. Privacy Policy You can accept or decline non-essential tracking.