Driver FixRecommendedSound, Wi-Fi or graphics acting up? Check drivers firstFind missing or outdated drivers fast.Check DriversOctober DealsAmazon USOctober deal check: compare before you payAmazon US: current deals, useful picks and tech finds.Check DealsPC HealthRecommendedCrashes, freezes, slowdowns? Check your PC nowSpot repairable issues before they interrupt work.Check PC×
Skip to content
World desk4 min

How JSON Objects and Arrays Map to Python Dictionaries and Lists

Python maps JSON objects to dictionaries and arrays to lists—but JSON is text, not a native Python structure, and not every language-specific value can be preserved when converting it.
Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

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.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

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.

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.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
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.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

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.

Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

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.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

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.

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.

Leave a Reply

Your email address will not be published. Required fields are marked *

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

More from the Wire

  1. World desk4 min
    How to Spot an AI Voice Scam Before Sending MoneyDon’t rely on how a caller sounds. Pause, call back through a known number, and verify the emergency with another trusted person before sending money.
  2. Mountain View desk4 min
    Google’s SynthID Detector: How to Check AI-Generated Images, Video and AudioGoogle’s SynthID Detector looks for an embedded watermark in supported images, video and audio. Here is what its results do—and do not—show.
  3. Redmond desk20 min
    How to create a link to File or Folder in Windows 11Windows 11 gives you several ways to point to a file or folder without moving or duplicating it. You can create a desktop shortcut,…
Recommended PC Tool
Recommended PC Tool
PC Slower Than It Used to Be?Free scan - under a minute
Outdated Drivers Are Slowing You DownFree scan - exact matches

Two free Windows tools

One Free Minute Could Fix That PC

Before you go - each of these free tools takes about a minute and tackles what quietly slows a Windows PC down.

Special offer. View Outbyte info, uninstall instructions, EULA, and Privacy Policy.