What is JSON? The format, and what your code does with it
Last updated: 2026-11-26
JSON is a text format for structured data, an open standard used to store data and send it between programs. It is built from objects, which pair names with values, and arrays, which are ordered lists, and people can read it as plain text. The text itself does nothing. A parser turns it into values in your programming language, and a serializer turns values back into text to send.
Start learning No account needed
1. What the format stores, and what the code does
JSON has six kinds of value. A number is written in decimal, can be negative, and may have a fraction or an exponent. A string is text in double quotes that holds Unicode characters and may be empty. A boolean is true or false, in lowercase. An array holds values in order and may be empty. An object holds name and value pairs, and each name, also called a key, is a string. The word null stands for an empty value. Objects and arrays can nest, so one document can carry an order, its address and its list of items.
JSON stands for JavaScript Object Notation. Wikipedia reports that Douglas Crockford defined the format around the start of this century and, with Chip Morningstar, sent its first message in April 2001. It grew out of JavaScript, yet it does not depend on that language, and many others can read and write it. So a server written in one language can send text that a client written in another can parse.
2. A worked example: parse an order, then reject a bad one
The document in this example is what a small shop might attach to an order. It is one object holding strings, a boolean, a null and an array of item objects with numbers, so all six kinds of value appear. The script parses it, reads fields, computes the line total, then tries the same text with one comma doubled. Python's json module is the parser:
Part of the order text, as it sits in the file:
"paid": true,
{"name": "notebook", "qty": 3, "price": 4.5},
{"name": "pen", "qty": 2, "price": 1.25}
"coupon": null,
The order document, parsed by json.loads:
order_id: A-1042 (string)
paid: True (boolean)
coupon: None (null: JSON's empty value)
items: 2 objects in an array
- notebook: qty 3 at 4.50
- pen: qty 2 at 1.25
line total the code computes: 16.00
The boundary between text and values, checked:
Python True is written true in JSON; None is written null.
The invalid variant (a doubled comma) is rejected at parse time:
Expecting property name enclosed in double quotes: line 9 column 18 (char 173)
By default json.loads accepts NaN. With parse_constant set:
NaN is not valid JSON
checks passed
Compare the first block of output with the second. In the text, paid is the lowercase word true and coupon is null. After parsing, the same fields are Python's True and None, values your code can branch on. The doubled comma changes one character, and the parser raises an error that names the line and column instead of returning part of the data. The last lines show one gap to know about: by default Python's module also accepts NaN, which is not valid JSON.
3. A common misconception: structured text is JSON
A dictionary printed from Python, an object literal copied from JavaScript source and a settings file with comments can all look like JSON. Strict JSON rejects what often sets them apart. Python prints booleans as True and False and usually wraps strings in single quotes, and neither is allowed. A trailing comma before a closing bracket or brace is not allowed either. JSON has no comment syntax, so variants such as JSONC add it. Keys must be strings, so a number used as a key has to be written in quotes.
Numbers need care too. The format does not distinguish integers from floating-point numbers, and languages may represent numbers differently, so some programs treat 42 and 42.0 as the same value and others do not. If exact amounts matter, as with money, check how your parser reads them.
4. Test yourself
Three questions before you scroll back. First: name the six kinds of value a JSON document can hold. Second: a field called paid is true; how is that value written in JSON text, and how does Python show it after parsing? Third: in the example, what was changed to break the document, and what did the parser do? Then check: number, string, boolean, array, object and null; true in the text and True in Python; a comma was doubled and the parser raised an error with its position. The one that took a second look is the part to practice.
JSON is widely used to pass data between programs, including web applications and servers. For a related structure that looks values up by name, see what is a hash table, for study habits around code, how to learn programming without copying code, and for exam practice, how to study for a computer science exam.
What the sources found, and their limits
Wikipedia, "JSON". It covers the definition, the value types, the history with Crockford and the April 2001 message, the lack of comments and trailing commas, and how numbers are treated. Source: JSON, read on 2026-11-25.
Python 3 documentation, "json", JSON encoder and decoder. It documents loads and dumps, the conversion between JSON values and Python objects, the JSONDecodeError for invalid documents, and the default handling of NaN and Infinity. Source: json, JSON encoder and decoder, read on 2026-11-25.
Limits: an encyclopedia article and a library reference, not a course text. The order document and its broken variant are ours, and scripts/what-is-json-worked-example.py runs them under Python 3. The Wikipedia article is CC BY-SA. The Python documentation page is licensed under the Python Software Foundation License Version 2.
How Professor Turing helps
Professor Turing is a tutor for adults learning any subject, in college or on their own. It asks you questions instead of giving the final answer, does not grade a bare guess, and remembers what you got wrong. No account is needed to start.
Bring the file or the error you are staring at, such as a JSONDecodeError with a line number. Its first reply asks what you already know before it teaches anything. If you answer with a bare guess, it asks how you got there instead of saying right or wrong, and when you stay stuck it changes its approach and makes the next step smaller instead of handing over the answer. Later in a session it can offer a short test without help, scored apart from the tutoring, so you can tell what you can do alone from what the tutor carried you through. You must be 18 or older, and guest conversations are deleted 7 days after the last activity.
FAQ
Is any structured text automatically JSON? No. JSON has a fixed grammar: names are strings in double quotes, the booleans are the lowercase words true and false, the empty value is null, there are no comments, and an object or array may not end with a trailing comma. A printed Python dictionary looks similar but typically uses single quotes and the capitalized True, False and None.
What does code actually do with JSON? Mainly two things. Parsing, which the Python documentation calls deserializing, reads the text and builds values in the language's own types. Serializing goes the other way, from values to text that can be stored or sent. When Python's parser meets text it cannot read, it raises JSONDecodeError with the position, although by default it also accepts NaN and Infinity, which JSON does not allow.
Start with what you're working on
Tell the tutor what you are parsing or building and let it ask you the questions.
Start learning No account needed
See also: what is a hash table · how to learn programming without copying code · how to study for a computer science exam · all study guides