JSON objects usually become Python dictionaries (dict), and JSON arrays become Python lists (list) when Python parses them with its built-in json module. JSON is text, though—not a Python or JavaScript data structure—so the parsed value depends on the JSON at the document’s root, and some language-specific values cannot make a faithful round trip.
What JSON objects and arrays mean
JSON is a text-based data-interchange format. It defines objects as collections of name/value pairs and arrays as ordered sequences of values. An object suits fields addressed by name, such as a person’s name; an array suits items whose sequence or position matters, such as a list of skills.
JSON.org notes that these structures have familiar counterparts across languages: objects are like records, dictionaries, or associative arrays, while arrays are like lists, vectors, or sequences. The JSON terms describe the format; each language chooses its own native representation. In Python, the standard decoder maps an object to a dictionary and an array to a list.
| JSON value | Python default after decoding | Example |
|---|---|---|
| Object | dict |
{"name": "Ari"} |
| Array | list |
["Python", "JSON"] |
| String | str |
"hello" |
| Integer-form number | int |
7 |
| Real-form number | float |
7.5 |
true / false |
True / False |
true |
null |
None |
null |
The conversions shown are Python’s defaults; see the Python 3.12 json documentation for conversion details and customization options.
#1 Best Overall
How to parse JSON into a dictionary or list in Python
Use json.loads() when the JSON is already in a Python string. Use json.load() when reading from a file-like object. The returned Python value follows the shape at the JSON document’s root.
import json
text = '{"name": "Ari", "skills": ["Python", "JSON"]}'
data = json.loads(text)
# data is a dict; data["skills"] is a list
print(data["name"]) # Ari
print(data["skills"][0]) # Python
The outer value here is an object, so data is a dictionary. Its skills field is an array, so that field becomes a list. Objects and arrays can nest in either direction, producing dictionaries that contain lists, lists that contain dictionaries, or deeper combinations.
Rank #2
A JSON document can start with an array or a scalar
A JSON document does not have to start with an object. For example, ["red", "green"] parses to a Python list, while 42 parses to an integer. If you expected a dictionary but received a list, inspect the JSON’s first structural value: a top-level array is valid JSON, not a decoding error. MDN’s guide to working with JSON also describes arrays and primitive values at the root.
How to turn a Python dictionary or list into JSON
Use json.dumps() to produce JSON text as a Python string, or json.dump() to write JSON to a file-like object. Python’s encoder supports dictionaries as JSON objects and lists or tuples as JSON arrays.
import json
data = {
"name": "Ari",
"skills": ["Python", "JSON"]
}
back_to_text = json.dumps(data)
print(back_to_text)
# {"name": "Ari", "skills": ["Python", "JSON"]}
json.dumps() returns str, not bytes. If a destination expects bytes, encode the resulting string or use an appropriate text stream. For a binary stream, passing the string directly is not the same as writing bytes.
JSON is not a JavaScript object literal
The name stands for “JavaScript Object Notation,” but JSON is a language-independent text format, not executable JavaScript syntax. As MDN explains, it is “a syntax for serializing objects, arrays, numbers, strings, booleans, and null.” A JavaScript object literal may look similar, but JSON has stricter rules.
- Property names and strings must use double quotes:
{"name": "Ari"}is valid JSON;{name: 'Ari'}is not. - JSON does not allow comments.
- JSON does not allow trailing commas after the last object property or array item.
These rules are why text copied from source code that resembles an object literal may fail in a JSON parser. MDN’s JSON reference outlines the format and its syntax constraints.
Why some native values do not survive JSON serialization
JSON has a limited set of value types: objects, arrays, strings, numbers, booleans, and null. It has no direct JSON value for values such as Python’s sets, dates, or functions, or JavaScript’s undefined, functions, symbols, dates, sets, and maps. A conversion therefore may omit a value, transform it, or fail; a JSON round trip is not a universal deep copy or a guarantee of native type preservation.
The Tool Desk
Outbyte Driver Updater FREEScan for outdated or missing drivers - takes under a minuteDriver Scan →Outbyte PC Repair FREERepair Windows errors before they cause bigger problemsFix Now →Best Value
Python-specific behavior
Python’s standard encoder handles basic supported types, but a custom type needs an explicit representation. The json module provides a default conversion hook and custom encoder support; the decoder also provides hooks for customized object handling. Use these only when the data contract defines how the custom value should be represented and reconstructed.
Python’s module also accepts NaN, Infinity, and -Infinity while decoding, and emits them by default while encoding. These are extensions, not values permitted by the JSON specification. Set allow_nan=False on json.dumps() to reject them during encoding.
JavaScript-specific behavior
JavaScript’s JSON.stringify() omits unsupported values such as undefined, functions, and symbols when they occur in objects, but converts them to null in arrays. It converts NaN and infinities to null. It throws for circular references and for BigInt unless custom handling is supplied. See MDN’s JSON.stringify() reference for the documented behavior.
Choose the structure that matches the data
| Question | Choose an object/dictionary when… | Choose an array/list when… |
|---|---|---|
| How will you access a value? | You need a named field, such as data["name"]. |
You need an item by position, such as data[0]. |
| What does order mean? | Values are associated with names; sequence is not the main way you identify a field. | The sequence or position carries meaning. |
| What does Python produce? | A dict. |
A list. |
For example, represent a person’s named fields as an object, and represent that person’s ordered steps or selected items as an array. Nested data can combine both: an object can have an array-valued field, as in the skills example above.
Free tools Windows power users keep installed
One-click scans. No signup required.
Handle untrusted JSON with care
Parsing is not risk-free just because JSON is a text format. Python’s documentation warns that malicious JSON can consume considerable CPU and memory, and recommends limiting the size of data being parsed. When accepting input from users or remote systems, enforce an appropriate size limit before decoding it.
Quick Recap
Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.




