Last modified: January 24, 2026
This article is written in: 🇺🇸
JSON, or JavaScript Object Notation, is a lightweight data-interchange format that is easy for humans to read and write and easy for machines to parse and generate. It is a text format that is completely language independent but uses conventions familiar to programmers of the C family of languages, including C, C++, C#, Java, JavaScript, Perl, Python, and many others.
Data Types: JSON supports a variety of data types including strings, numbers, booleans, arrays, and objects (key-value pairs).
Syntax: JSON syntax is derived from JavaScript object notation syntax, but the JSON format is text only. Code for reading and generating JSON data can be written in any programming language.
{}: An object can be thought of as an unordered set of name/value pairs. An object begins with { (left brace) and ends with } (right brace). Each name is followed by : (colon) and the name/value pairs are separated by , (comma).[]: An array is an ordered collection of values. An array begins with [ (left bracket) and ends with ] (right bracket). Values are separated by , (comma).Here's a simple example of a JSON file:
{
"employee": {
"name": "John Doe",
"age": 30,
"department": "Engineering",
"address": {
"street": "1234 Main St",
"city": "Anytown",
"state": "CA",
"zipCode": "12345"
},
"skills": ["Java", "C#", "Python"]
}
}
While both JSON and XML can be used to store and exchange data, JSON is often preferred due to its simplicity and speed. JSON is easier to read and write, and faster to parse and generate than XML.
| Feature | JSON (JavaScript Object Notation) | XML (eXtensible Markup Language) |
| Format | Lightweight and text-based. | Verbose and document-based format. |
| Readability | Generally easier to read due to its concise format. | Less human-readable due to more verbose nature. |
| Data Types | Supports basic data types like string, number, array, boolean, and null. | Does not have built-in support for data types; everything is a string. |
| Parsing | Easy to parse with standard JavaScript functions. | Requires a parser to read and manipulate. |
| Size | Typically smaller, making it faster to transmit. | Larger file sizes due to additional markup elements. |
| Extensibility | Not as extensible due to its fixed structure. | Highly extensible and allows for custom-defined tags and structures. |
| Metadata | Limited support for metadata. | Excellent support for metadata. |
| Comments | Does not support comments. | Supports comments. |
| Security | Considered more secure as it is less prone to entity and DTD attacks. | Prone to certain types of attacks like entity and DTD attacks. |
| Array Representation | Uses square brackets for arrays. | Uses custom tag names for arrays; no built-in array representation. |
| Use Cases | Often used in web services and APIs due to its compatibility with JavaScript and lightweight nature. | Preferred for complex document structures and when metadata is crucial. |