{"id":138788,"date":"2025-11-28T18:22:00","date_gmt":"2025-11-28T16:22:00","guid":{"rendered":"https:\/\/www.javacodegeeks.com\/?p=138788"},"modified":"2025-11-27T14:04:15","modified_gmt":"2025-11-27T12:04:15","slug":"how-to-work-with-json-in-python","status":"publish","type":"post","link":"https:\/\/www.javacodegeeks.com\/how-to-work-with-json-in-python.html","title":{"rendered":"How to Work with JSON in Python"},"content":{"rendered":"<p>JSON (JavaScript Object Notation) is one of the most common formats for storing and exchanging data across applications and APIs. Python provides a built-in <code>json<\/code> module that makes it easy to parse, read, write, and manipulate JSON documents. This article covers JSON structure, parsing nested objects and arrays, working with files, and managing common JSON parsing errors.<\/p>\n<h2 class=\"wp-block-heading\">1. Understanding JSON Structure<\/h2>\n<p><a href=\"https:\/\/www.json.org\/json-en.html\" target=\"_blank\" rel=\"noreferrer noopener\">JSON<\/a> is a lightweight, structured text format used to represent data as <strong>key-value<\/strong> pairs and arrays. A JSON document begins with either an <strong>object<\/strong> (<code>{}<\/code>) or an <strong>array<\/strong> (<code>[]<\/code>). Inside a JSON object, we can include zero, one, or many key-value pairs. When we define multiple key-value pairs, each one must be separated with a comma.<\/p>\n<p>A key-value pair consists of a key on the left and a value on the right, separated by a colon <code>(:)<\/code>. JSON keys must always be double-quoted strings, unlike Python, which allows single quotes. JSON values must be one of the supported data types listed below.<\/p>\n<p><strong>JSON Data Types<\/strong><\/p>\n<div class=\"wp-block-group\">\n<div class=\"wp-block-group__inner-container is-layout-constrained wp-block-group-is-layout-constrained\">\n<figure class=\"wp-block-table is-style-stripes\">\n<table>\n<thead>\n<tr>\n<th>JSON Data Type<\/th>\n<th>Description<\/th>\n<\/tr>\n<\/thead>\n<tbody>\n<tr>\n<td>object<\/td>\n<td>A collection of key-value pairs enclosed in <code>{}<\/code><\/td>\n<\/tr>\n<tr>\n<td>array<\/td>\n<td>An ordered list of values inside <code>[]<\/code><\/td>\n<\/tr>\n<tr>\n<td>string<\/td>\n<td>Text wrapped in double quotes <code>\"\"<\/code><\/td>\n<\/tr>\n<tr>\n<td>number<\/td>\n<td>Integers or floating-point numbers<\/td>\n<\/tr>\n<tr>\n<td>boolean<\/td>\n<td><code>true<\/code> or <code>false<\/code> without quotes<\/td>\n<\/tr>\n<tr>\n<td>null<\/td>\n<td>Represents an empty value using <code>null<\/code><\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/figure>\n<\/div>\n<\/div>\n<p>JSON supports nesting, meaning objects can contain arrays, and arrays can contain objects. This makes JSON flexible enough to represent complex structures. Python\u2019s <code>json<\/code> module can convert common Python data types into their JSON equivalents. The table below shows the mapping:<\/p>\n<p><strong>Python to JSON Data Type Mapping<\/strong><\/p>\n<figure class=\"wp-block-table is-style-stripes\">\n<table>\n<thead>\n<tr>\n<th>Python Type<\/th>\n<th>JSON Equivalent<\/th>\n<\/tr>\n<\/thead>\n<tbody>\n<tr>\n<td>dict<\/td>\n<td>object<\/td>\n<\/tr>\n<tr>\n<td>list<\/td>\n<td>array<\/td>\n<\/tr>\n<tr>\n<td>tuple<\/td>\n<td>array<\/td>\n<\/tr>\n<tr>\n<td>str<\/td>\n<td>string<\/td>\n<\/tr>\n<tr>\n<td>int<\/td>\n<td>number<\/td>\n<\/tr>\n<tr>\n<td>float<\/td>\n<td>number<\/td>\n<\/tr>\n<tr>\n<td>True<\/td>\n<td>true<\/td>\n<\/tr>\n<tr>\n<td>False<\/td>\n<td>false<\/td>\n<\/tr>\n<tr>\n<td>None<\/td>\n<td>null<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/figure>\n<p>Note that Python lists and tuples both convert to JSON arrays. When converting JSON back to Python, arrays always become lists, meaning the original type may not be preserved. <\/p>\n<p><strong>Basic Parsing<\/strong> <strong>Example<\/strong><\/p>\n<pre class=\"brush:python\">\nimport json\n\n# Sample JSON string\njson_string = '{\"name\": Thomas\", \"age\": 25, \"city\": \"New York\"}'\n\n# Parse JSON string into a Python dictionary\ndata = json.loads(json_string)\n\n# Accessing values\nprint(\"Name:\", data[\"name\"])\nprint(\"Age:\", data[\"age\"])\nprint(\"City:\", data[\"city\"])\n<\/pre>\n<p>This example begins by importing the <code>json<\/code> module and defining a string that contains a JSON object. The <code>json.loads()<\/code> method converts the JSON string into a Python <a href=\"https:\/\/www.javacodegeeks.com\/2020\/07\/what-is-a-dictionary-in-python.html\" target=\"_blank\" rel=\"noreferrer noopener\">dictionary<\/a>, allowing direct access to keys just as with any normal dictionary. The output shows how to retrieve specific fields (<code>name,age, city<\/code>). This simple pattern forms the foundation for all JSON parsing in Python.<\/p>\n<p><strong>Output<\/strong><\/p>\n<pre class=\"brush:plain\">\nName: Thomas\nAge: 25\nCity: New York\n<\/pre>\n<h2 class=\"wp-block-heading\">2. Nested JSON Objects Handling<\/h2>\n<p>JSON objects can contain other objects, forming a nested structure. These structures are common in configuration files, API responses, and hierarchical datasets. Accessing nested values requires chaining dictionary keys at each level.<\/p>\n<pre class=\"brush:python\">\nimport json\n\n# Nested JSON string\nnested_json_string = \"\"\"\n{\n    \"person\": {\n        \"name\": \"Mr Fish\",\n        \"age\": 30,\n        \"address\": {\n            \"street\": \"123 Maple St\",\n            \"city\": \"Los Angeles\"\n        }\n    }\n}\n\"\"\"\n\n# Parse JSON string\ndata = json.loads(nested_json_string)\n\n# Access nested values\nprint(\"Name:\", data[\"person\"][\"name\"])\nprint(\"Age:\", data[\"person\"][\"age\"])\nprint(\"Street:\", data[\"person\"][\"address\"][\"street\"])\n<\/pre>\n<p>Here, the <code>person<\/code> key contains another JSON object, and the <code>address<\/code> key is nested further. Accessing nested values simply involves chaining keys (e.g., <code>data[\"person\"][\"name\"]<\/code>). This pattern is common when reading API responses where data is grouped hierarchically.<div style=\"display:inline-block; margin: 15px 0;\"> <div id=\"adngin-JavaCodeGeeks_incontent_video-0\" style=\"display:inline-block;\"><\/div> <\/div><\/p>\n<p><strong>Output<\/strong><\/p>\n<pre class=\"brush:plain\">\nName: Mr Fish\nAge: 30\nStreet: 123 Maple St\n<\/pre>\n<h2 class=\"wp-block-heading\">3. Parsing JSON Arrays<\/h2>\n<p>JSON arrays are lists of items enclosed in square brackets. Each item can be a simple value or a nested JSON object. Python converts JSON arrays into lists, which can be iterated over.<\/p>\n<pre class=\"brush:python\">\nimport json\n\n# JSON array string\npeople = \"\"\"\n[\n    {\"name\": \"Thomas\", \"age\": 25},\n    {\"name\": \"Eve\", \"age\": 30},\n    {\"name\": \"John\", \"age\": 22}\n]\n\"\"\"\n\n# Parse JSON array\ndata = json.loads(people)\n\nprint(f\"Total persons: {len(data)}\")\n\n# Loop through array\nfor person in data:\n    print(f\"Name: {person['name']}, Age: {person['age']}\")\n<\/pre>\n<p>The JSON array contains three objects, each representing a person. After parsing with <code>json.loads()<\/code>, the data becomes a list of dictionaries in Python. The <code>len()<\/code> function returns the number of items, and the loop prints each person\u2019s details.<\/p>\n<p><strong>Output<\/strong><\/p>\n<pre class=\"brush:plain\">\nTotal persons: 3\nName: Thomas, Age: 25\nName: Eve, Age: 30\nName: John, Age: 22\n<\/pre>\n<h2 class=\"wp-block-heading\">4. Reading JSON From Files<\/h2>\n<p>JSON files are widely used to store configuration settings, structured logs, application data, and more. Python\u2019s <code>json.load()<\/code> function allows you to parse JSON directly from a file.<\/p>\n<pre class=\"brush:python\">\nimport json\n\n# Open JSON file and parse\nwith open(\"data.json\", \"r\") as file:\n    data = json.load(file)\n\nprint(data[\"name\"])\nprint(data[\"age\"])\n<\/pre>\n<p>This example reads a JSON file using <code>json.load()<\/code>, which directly parses the file contents into Python objects without manually reading strings. Using <code>with open(...)<\/code> ensures the file is properly closed after reading. Accessing the parsed data works the same way as any dictionary.<\/p>\n<p>Sample <code>data.json<\/code><\/p>\n<pre class=\"brush:javascript\">\n{\n    \"name\": \"Thomas\",\n    \"age\": 25,\n    \"city\": \"New York\"\n}\n<\/pre>\n<p><strong>Writing JSON to Files<\/strong><\/p>\n<p>To save JSON data to a file, Python provides the <code>json.dump()<\/code> function. This writes Python data as JSON directly to disk.<\/p>\n<pre class=\"brush:python\">\nimport json\n\ndata = {\"name\": \"Bob\", \"age\": 30, \"city\": \"Los Angeles\"}\n\nwith open(\"output.json\", \"w\") as file:\n    json.dump(data, file, indent=4)\n<\/pre>\n<p>This code creates a JSON file named <code>output.json<\/code> containing the given data. Using <code>indent<\/code> ensures it is stored in a readable format. Writing JSON files is common when saving user preferences, logs, structured data, or exporting information.<\/p>\n<p><strong>Output<\/strong> (<code>output.json<\/code>)<\/p>\n<pre class=\"brush:javascript\">\n{\n    \"name\": \"Bob\",\n    \"age\": 30,\n    \"city\": \"Los Angeles\"\n}\n<\/pre>\n<h2 class=\"wp-block-heading\">5. Modifying JSON Data<\/h2>\n<p>Once JSON is parsed into Python objects, we can modify it just like any dictionary or list. This includes adding new fields, updating existing values, and removing elements entirely. These operations are useful when cleaning data, transforming API responses, updating configuration files, or preparing JSON before saving or sending it back to another service.<\/p>\n<p><strong>Adding an Element<\/strong><\/p>\n<p>We can add elements to a parsed JSON object (dictionary) by assigning new <strong>key-value<\/strong> pairs. If we&#8217;re working with arrays (lists), we can append new items.<\/p>\n<pre class=\"brush:python\">\nimport json\n\nemployee_json = \"\"\"\n{\n    \"name\": \"Helen\",\n    \"role\": \"Developer\",\n    \"skills\": [\"Python\", \"SQL\"]\n}\n\"\"\"\n\nemployee = json.loads(employee_json)\n\n# Add new elements\nemployee[\"location\"] = \"Remote\"\nemployee[\"skills\"].append(\"Docker\")\n\nupdated_json = json.dumps(employee, indent=4)\nprint(updated_json)\n<\/pre>\n<p>This example adds a new top-level field called <code>location<\/code> and appends a new skill (<code>\"Docker\"<\/code>) to the existing list of skills. JSON parsed into Python structures behaves exactly like normal dictionaries and lists, so adding new keys or appending items works naturally. After making the changes, <code>json.dumps()<\/code> regenerates a formatted JSON string containing the new fields.<\/p>\n<p><strong>Output<\/strong><\/p>\n<pre class=\"brush:javascript\">\n{\n    \"name\": \"Helen\",\n    \"role\": \"Developer\",\n    \"skills\": [\n        \"Python\",\n        \"SQL\",\n        \"Docker\"\n    ],\n    \"location\": \"Remote\"\n}\n<\/pre>\n<p><strong>Updating an Element<\/strong><\/p>\n<p>To update an existing value, overwrite it by assigning a new value to the corresponding key.<\/p>\n<pre class=\"brush:python\">\nimport json\n\nemployee_json = \"\"\"\n{\n    \"name\": \"Helen\",\n    \"role\": \"Developer\",\n    \"skills\": [\"Python\", \"SQL\"]\n}\n\"\"\"\n\nemployee = json.loads(employee_json)\n\n# Update existing elements\nemployee[\"role\"] = \"Senior Developer\"\nemployee[\"skills\"][0] = \"Advanced Python\"\n\nupdated_json = json.dumps(employee, indent=4)\nprint(updated_json)\n<\/pre>\n<p>Here, the <code>role<\/code> field is updated from <code>\"Developer\"<\/code> to <code>\"Senior Developer\"<\/code>, and the first skill is modified to <code>\"Advanced Python\"<\/code>. Because JSON objects convert to Python dictionaries and arrays convert to lists, updating any part of the structure is simply direct assignment or list modification. The resulting JSON reflects the updated data.<\/p>\n<p><strong>Output<\/strong><\/p>\n<pre class=\"brush:javascript\">\n{\n    \"name\": \"Helen\",\n    \"role\": \"Senior Developer\",\n    \"skills\": [\n        \"Advanced Python\",\n        \"SQL\"\n    ]\n}\n<\/pre>\n<p><strong>Deleting an Element<\/strong><\/p>\n<p>Python lets us remove JSON elements using <code>del<\/code> for dictionary keys or <code>remove()<\/code> \/ <code>pop()<\/code> for list items.<\/p>\n<pre class=\"brush:python\">\nimport json\n\nemployee_json = \"\"\"\n{\n    \"name\": \"Helen\",\n    \"role\": \"Developer\",\n    \"skills\": [\"Python\", \"SQL\", \"Docker\"],\n    \"location\": \"Remote\"\n}\n\"\"\"\n\nemployee = json.loads(employee_json)\n\n# Delete elements\ndel employee[\"location\"]  # Remove a field\nemployee[\"skills\"].remove(\"SQL\")  # Remove a list item\n\nupdated_json = json.dumps(employee, indent=4)\nprint(updated_json)\n<\/pre>\n<p>In this example, the <code>location<\/code> key is removed using <code>del<\/code>, while <code>\"SQL\"<\/code> is removed from the skills list using <code>remove()<\/code>. These operations work on Python structures but directly affect the resulting JSON when serialized back.<\/p>\n<p><strong>Output<\/strong><\/p>\n<pre class=\"brush:javascript\">\n{\n    \"name\": \"Helen\",\n    \"role\": \"Developer\",\n    \"skills\": [\n        \"Python\",\n        \"Docker\"\n    ]\n}\n<\/pre>\n<h2 class=\"wp-block-heading\">6. Handling JSON Parsing Errors<\/h2>\n<p>When working with JSON in Python, errors can occur for many reasons, such as invalid JSON formatting, incorrect data types, missing files, or a lack of file permissions. Python provides several exceptions that help us detect and recover from these problems. By wrapping our JSON operations inside <code>try\u2013except<\/code> blocks, we can prevent our program from crashing and respond in a controlled way.<\/p>\n<p>Using <code>try\u2013except<\/code> allows our application to gracefully handle errors like malformed JSON, missing files, incorrect types, or restricted access while providing helpful feedback to users or logs.<\/p>\n<p><strong>Using <\/strong><code>try\u2013except<\/code><strong> When Working With JSON<\/strong><\/p>\n<p>A <code>try\u2013except<\/code> block lets us test a block of code and catch possible exceptions. Here is the basic pattern when working with JSON:<\/p>\n<pre class=\"brush:python\">\nimport json\n\ntry:\n    with open(\"data.json\") as file:\n        data = json.load(file)\n    print(\"JSON loaded successfully\")\nexcept json.JSONDecodeError:\n    print(\"Error: The JSON file contains invalid syntax.\")\nexcept FileNotFoundError:\n    print(\"Error: The file does not exist.\")\nexcept PermissionError:\n    print(\"Error: You do not have permission to read the file.\")\nexcept TypeError:\n    print(\"Error: Incorrect data type was used.\")\n<\/pre>\n<p>This structure ensures our program remains stable even when something goes wrong.<\/p>\n<p><strong>Common JSON Parsing Errors<\/strong><\/p>\n<p>Below are some of the most common JSON-related errors<\/p>\n<p><strong>Invalid JSON Syntax<\/strong> (<code>json.JSONDecodeError<\/code>)<\/p>\n<p>A <code>JSONDecodeError<\/code> occurs when the JSON string is improperly formatted. JSON requires strict syntax rules: keys must be quoted, commas must be correctly placed, and strings must use double quotes.<\/p>\n<pre class=\"brush:python\">\nimport json\n\nbad_json = '{ \"name\": \"John\", \"age\": 30,, }'\n\ntry:\n    data = json.loads(bad_json)\nexcept json.JSONDecodeError as e:\n    print(\"JSONDecodeError occurred:\", e)\n<\/pre>\n<p><strong>Output<\/strong><\/p>\n<pre class=\"brush:bash\">\nJSONDecodeError occurred: Expecting property name enclosed in double quotes: line 1 column 29 (char 28)\n<\/pre>\n<p>This error happens when the JSON data does not follow the required syntax rules. Fixing it often involves adding missing quotes, removing trailing commas, or correcting malformed structures.<\/p>\n<p><strong>Incorrect Data Type <\/strong>(<code>TypeError<\/code>)<\/p>\n<p>This happens when we pass the wrong type into a JSON function.<\/p>\n<pre class=\"brush:python\">\nimport json\n\ntry:\n    json.loads(123)  # expecting a string, not an integer\nexcept TypeError as e:\n    print(\"TypeError occurred:\", e)\n<\/pre>\n<p><strong>Output<\/strong><\/p>\n<pre class=\"brush:bash\">\nTypeError occurred: the JSON object must be str, bytes or bytearray, not int\n<\/pre>\n<p><code>json.loads()<\/code> accepts only strings, bytes, or bytearrays, so the solution is to ensure you always pass a properly formatted JSON string when calling the function.<\/p>\n<p><strong>File Does Not Exist<\/strong> (<code>FileNotFoundError<\/code>)<\/p>\n<p>A <code>FileNotFoundError<\/code> is raised when attempting to load a JSON file that does not exist at the provided path.<\/p>\n<pre class=\"brush:python\">\nimport json\n\ntry:\n    with open(\"missing.json\", \"r\") as file:\n        data = json.load(file)\nexcept FileNotFoundError as e:\n    print(\"File error:\", e)\n<\/pre>\n<p><strong>Output<\/strong><\/p>\n<pre class=\"brush:bash\">\nFile error: [Errno 2] No such file or directory: 'missing.json'\n<\/pre>\n<p>Make sure the file is located correctly or use an absolute path, and consider checking for its existence before attempting to read it.<\/p>\n<p><strong>Handling<\/strong> <code>PermissionError<\/code> (<strong>No Access to File<\/strong>)<\/p>\n<p>A <code>PermissionError<\/code> occurs when Python finds the file but does not have permission to read it. This can happen with protected system files or files lacking read permissions.<\/p>\n<pre class=\"brush:python\">\nimport json\n\ntry:\n    with open(\"\/protected\/data.json\", \"r\") as file:\n        data = json.load(file)\nexcept PermissionError as e:\n    print(\"Permission error:\", e)\n<\/pre>\n<p><strong>Output<\/strong><\/p>\n<pre class=\"brush:bash\">\nPermission error: [Errno 13] Permission denied: '\/protected\/data.json'\n<\/pre>\n<p>Even if a file exists, the operating system may block access for security reasons, so adjusting permissions, using user-accessible directories, or running the script with appropriate access rights ensures our program can read the file safely.<\/p>\n<h2 class=\"wp-block-heading\">7. Conclusion<\/h2>\n<p>In this article, we explored how to parse, manipulate, and handle JSON data in Python, including understanding JSON structure, working with nested objects and arrays, reading and writing files, modifying data, and handling common errors. Using Python\u2019s built-in <code>json<\/code> module with proper error handling allows Python developers to efficiently process JSON for APIs, applications, and configuration management.<\/p>\n<h2 class=\"wp-block-heading\">8. Download the Source Code<\/h2>\n<p>This article covered how to parse JSON in Python with examples.<\/p>\n<div class=\"download\"><strong>Download<\/strong><br \/>\nYou can download the full source code of this example here: <a href=\"https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2025\/11\/basic_parsing.zip\"><strong>how to parse json in python<\/strong><\/a>\n<\/div>\n","protected":false},"excerpt":{"rendered":"<p>JSON (JavaScript Object Notation) is one of the most common formats for storing and exchanging data across applications and APIs. Python provides a built-in json module that makes it easy to parse, read, write, and manipulate JSON documents. This article covers JSON structure, parsing nested objects and arrays, working with files, and managing common JSON &hellip;<\/p>\n","protected":false},"author":128888,"featured_media":219,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1878],"tags":[69,4835,224],"class_list":["post-138788","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-python","tag-json","tag-json-parsing-2","tag-python"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v27.5 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>How to Work with JSON in Python - Java Code Geeks<\/title>\n<meta name=\"description\" content=\"Learn how to parse JSON in Python with examples, covering basic parsing, nested objects, arrays, file handling, and error management.\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.javacodegeeks.com\/how-to-work-with-json-in-python.html\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"How to Work with JSON in Python - Java Code Geeks\" \/>\n<meta property=\"og:description\" content=\"Learn how to parse JSON in Python with examples, covering basic parsing, nested objects, arrays, file handling, and error management.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.javacodegeeks.com\/how-to-work-with-json-in-python.html\" \/>\n<meta property=\"og:site_name\" content=\"Java Code Geeks\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/javacodegeeks\" \/>\n<meta property=\"article:author\" content=\"https:\/\/web.facebook.com\/omos.aziegbe\" \/>\n<meta property=\"article:published_time\" content=\"2025-11-28T16:22:00+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2012\/10\/python-logo.jpg\" \/>\n\t<meta property=\"og:image:width\" content=\"150\" \/>\n\t<meta property=\"og:image:height\" content=\"150\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/jpeg\" \/>\n<meta name=\"author\" content=\"Omozegie Aziegbe\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@https:\/\/twitter.com\/OAziegbe\" \/>\n<meta name=\"twitter:site\" content=\"@javacodegeeks\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Omozegie Aziegbe\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"7 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/how-to-work-with-json-in-python.html#article\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/how-to-work-with-json-in-python.html\"},\"author\":{\"name\":\"Omozegie Aziegbe\",\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/#\\\/schema\\\/person\\\/7d3eac6e45542536e961129ae0fb453e\"},\"headline\":\"How to Work with JSON in Python\",\"datePublished\":\"2025-11-28T16:22:00+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/how-to-work-with-json-in-python.html\"},\"wordCount\":1351,\"commentCount\":0,\"publisher\":{\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/#organization\"},\"image\":{\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/how-to-work-with-json-in-python.html#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/www.javacodegeeks.com\\\/wp-content\\\/uploads\\\/2012\\\/10\\\/python-logo.jpg\",\"keywords\":[\"JSON\",\"json-parsing\",\"Python\"],\"articleSection\":[\"Python\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\\\/\\\/www.javacodegeeks.com\\\/how-to-work-with-json-in-python.html#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/how-to-work-with-json-in-python.html\",\"url\":\"https:\\\/\\\/www.javacodegeeks.com\\\/how-to-work-with-json-in-python.html\",\"name\":\"How to Work with JSON in Python - Java Code Geeks\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/how-to-work-with-json-in-python.html#primaryimage\"},\"image\":{\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/how-to-work-with-json-in-python.html#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/www.javacodegeeks.com\\\/wp-content\\\/uploads\\\/2012\\\/10\\\/python-logo.jpg\",\"datePublished\":\"2025-11-28T16:22:00+00:00\",\"description\":\"Learn how to parse JSON in Python with examples, covering basic parsing, nested objects, arrays, file handling, and error management.\",\"breadcrumb\":{\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/how-to-work-with-json-in-python.html#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/www.javacodegeeks.com\\\/how-to-work-with-json-in-python.html\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/how-to-work-with-json-in-python.html#primaryimage\",\"url\":\"https:\\\/\\\/www.javacodegeeks.com\\\/wp-content\\\/uploads\\\/2012\\\/10\\\/python-logo.jpg\",\"contentUrl\":\"https:\\\/\\\/www.javacodegeeks.com\\\/wp-content\\\/uploads\\\/2012\\\/10\\\/python-logo.jpg\",\"width\":150,\"height\":150},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/how-to-work-with-json-in-python.html#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\\\/\\\/www.javacodegeeks.com\\\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Web Development\",\"item\":\"https:\\\/\\\/www.javacodegeeks.com\\\/category\\\/web-development\"},{\"@type\":\"ListItem\",\"position\":3,\"name\":\"Python\",\"item\":\"https:\\\/\\\/www.javacodegeeks.com\\\/category\\\/web-development\\\/python\"},{\"@type\":\"ListItem\",\"position\":4,\"name\":\"How to Work with JSON in Python\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/#website\",\"url\":\"https:\\\/\\\/www.javacodegeeks.com\\\/\",\"name\":\"Java Code Geeks\",\"description\":\"Java Developers Resource Center\",\"publisher\":{\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/#organization\"},\"alternateName\":\"JCG\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\\\/\\\/www.javacodegeeks.com\\\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Organization\",\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/#organization\",\"name\":\"Exelixis Media P.C.\",\"url\":\"https:\\\/\\\/www.javacodegeeks.com\\\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/#\\\/schema\\\/logo\\\/image\\\/\",\"url\":\"https:\\\/\\\/www.javacodegeeks.com\\\/wp-content\\\/uploads\\\/2022\\\/06\\\/exelixis-logo.png\",\"contentUrl\":\"https:\\\/\\\/www.javacodegeeks.com\\\/wp-content\\\/uploads\\\/2022\\\/06\\\/exelixis-logo.png\",\"width\":864,\"height\":246,\"caption\":\"Exelixis Media P.C.\"},\"image\":{\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/#\\\/schema\\\/logo\\\/image\\\/\"},\"sameAs\":[\"https:\\\/\\\/www.facebook.com\\\/javacodegeeks\",\"https:\\\/\\\/x.com\\\/javacodegeeks\"]},{\"@type\":\"Person\",\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/#\\\/schema\\\/person\\\/7d3eac6e45542536e961129ae0fb453e\",\"name\":\"Omozegie Aziegbe\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/wp-content\\\/uploads\\\/2023\\\/12\\\/cropped-jcg_profile_pic-96x96.jpg\",\"url\":\"https:\\\/\\\/www.javacodegeeks.com\\\/wp-content\\\/uploads\\\/2023\\\/12\\\/cropped-jcg_profile_pic-96x96.jpg\",\"contentUrl\":\"https:\\\/\\\/www.javacodegeeks.com\\\/wp-content\\\/uploads\\\/2023\\\/12\\\/cropped-jcg_profile_pic-96x96.jpg\",\"caption\":\"Omozegie Aziegbe\"},\"description\":\"Omos Aziegbe is a technical writer and web\\\/application developer with a BSc in Computer Science and Software Engineering from the University of Bedfordshire. Specializing in Java enterprise applications with the Jakarta EE framework, Omos also works with HTML5, CSS, and JavaScript for web development. As a freelance web developer, Omos combines technical expertise with research and writing on topics such as software engineering, programming, web application development, computer science, and technology.\",\"sameAs\":[\"https:\\\/\\\/web.facebook.com\\\/omos.aziegbe\",\"https:\\\/\\\/www.linkedin.com\\\/in\\\/omosaziegbe\\\/\",\"https:\\\/\\\/x.com\\\/https:\\\/\\\/twitter.com\\\/OAziegbe\"],\"url\":\"https:\\\/\\\/www.javacodegeeks.com\\\/author\\\/omozegie-aziegbe\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"How to Work with JSON in Python - Java Code Geeks","description":"Learn how to parse JSON in Python with examples, covering basic parsing, nested objects, arrays, file handling, and error management.","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/www.javacodegeeks.com\/how-to-work-with-json-in-python.html","og_locale":"en_US","og_type":"article","og_title":"How to Work with JSON in Python - Java Code Geeks","og_description":"Learn how to parse JSON in Python with examples, covering basic parsing, nested objects, arrays, file handling, and error management.","og_url":"https:\/\/www.javacodegeeks.com\/how-to-work-with-json-in-python.html","og_site_name":"Java Code Geeks","article_publisher":"https:\/\/www.facebook.com\/javacodegeeks","article_author":"https:\/\/web.facebook.com\/omos.aziegbe","article_published_time":"2025-11-28T16:22:00+00:00","og_image":[{"width":150,"height":150,"url":"https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2012\/10\/python-logo.jpg","type":"image\/jpeg"}],"author":"Omozegie Aziegbe","twitter_card":"summary_large_image","twitter_creator":"@https:\/\/twitter.com\/OAziegbe","twitter_site":"@javacodegeeks","twitter_misc":{"Written by":"Omozegie Aziegbe","Est. reading time":"7 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/www.javacodegeeks.com\/how-to-work-with-json-in-python.html#article","isPartOf":{"@id":"https:\/\/www.javacodegeeks.com\/how-to-work-with-json-in-python.html"},"author":{"name":"Omozegie Aziegbe","@id":"https:\/\/www.javacodegeeks.com\/#\/schema\/person\/7d3eac6e45542536e961129ae0fb453e"},"headline":"How to Work with JSON in Python","datePublished":"2025-11-28T16:22:00+00:00","mainEntityOfPage":{"@id":"https:\/\/www.javacodegeeks.com\/how-to-work-with-json-in-python.html"},"wordCount":1351,"commentCount":0,"publisher":{"@id":"https:\/\/www.javacodegeeks.com\/#organization"},"image":{"@id":"https:\/\/www.javacodegeeks.com\/how-to-work-with-json-in-python.html#primaryimage"},"thumbnailUrl":"https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2012\/10\/python-logo.jpg","keywords":["JSON","json-parsing","Python"],"articleSection":["Python"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/www.javacodegeeks.com\/how-to-work-with-json-in-python.html#respond"]}]},{"@type":"WebPage","@id":"https:\/\/www.javacodegeeks.com\/how-to-work-with-json-in-python.html","url":"https:\/\/www.javacodegeeks.com\/how-to-work-with-json-in-python.html","name":"How to Work with JSON in Python - Java Code Geeks","isPartOf":{"@id":"https:\/\/www.javacodegeeks.com\/#website"},"primaryImageOfPage":{"@id":"https:\/\/www.javacodegeeks.com\/how-to-work-with-json-in-python.html#primaryimage"},"image":{"@id":"https:\/\/www.javacodegeeks.com\/how-to-work-with-json-in-python.html#primaryimage"},"thumbnailUrl":"https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2012\/10\/python-logo.jpg","datePublished":"2025-11-28T16:22:00+00:00","description":"Learn how to parse JSON in Python with examples, covering basic parsing, nested objects, arrays, file handling, and error management.","breadcrumb":{"@id":"https:\/\/www.javacodegeeks.com\/how-to-work-with-json-in-python.html#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.javacodegeeks.com\/how-to-work-with-json-in-python.html"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.javacodegeeks.com\/how-to-work-with-json-in-python.html#primaryimage","url":"https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2012\/10\/python-logo.jpg","contentUrl":"https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2012\/10\/python-logo.jpg","width":150,"height":150},{"@type":"BreadcrumbList","@id":"https:\/\/www.javacodegeeks.com\/how-to-work-with-json-in-python.html#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/www.javacodegeeks.com\/"},{"@type":"ListItem","position":2,"name":"Web Development","item":"https:\/\/www.javacodegeeks.com\/category\/web-development"},{"@type":"ListItem","position":3,"name":"Python","item":"https:\/\/www.javacodegeeks.com\/category\/web-development\/python"},{"@type":"ListItem","position":4,"name":"How to Work with JSON in Python"}]},{"@type":"WebSite","@id":"https:\/\/www.javacodegeeks.com\/#website","url":"https:\/\/www.javacodegeeks.com\/","name":"Java Code Geeks","description":"Java Developers Resource Center","publisher":{"@id":"https:\/\/www.javacodegeeks.com\/#organization"},"alternateName":"JCG","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.javacodegeeks.com\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/www.javacodegeeks.com\/#organization","name":"Exelixis Media P.C.","url":"https:\/\/www.javacodegeeks.com\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.javacodegeeks.com\/#\/schema\/logo\/image\/","url":"https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2022\/06\/exelixis-logo.png","contentUrl":"https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2022\/06\/exelixis-logo.png","width":864,"height":246,"caption":"Exelixis Media P.C."},"image":{"@id":"https:\/\/www.javacodegeeks.com\/#\/schema\/logo\/image\/"},"sameAs":["https:\/\/www.facebook.com\/javacodegeeks","https:\/\/x.com\/javacodegeeks"]},{"@type":"Person","@id":"https:\/\/www.javacodegeeks.com\/#\/schema\/person\/7d3eac6e45542536e961129ae0fb453e","name":"Omozegie Aziegbe","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2023\/12\/cropped-jcg_profile_pic-96x96.jpg","url":"https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2023\/12\/cropped-jcg_profile_pic-96x96.jpg","contentUrl":"https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2023\/12\/cropped-jcg_profile_pic-96x96.jpg","caption":"Omozegie Aziegbe"},"description":"Omos Aziegbe is a technical writer and web\/application developer with a BSc in Computer Science and Software Engineering from the University of Bedfordshire. Specializing in Java enterprise applications with the Jakarta EE framework, Omos also works with HTML5, CSS, and JavaScript for web development. As a freelance web developer, Omos combines technical expertise with research and writing on topics such as software engineering, programming, web application development, computer science, and technology.","sameAs":["https:\/\/web.facebook.com\/omos.aziegbe","https:\/\/www.linkedin.com\/in\/omosaziegbe\/","https:\/\/x.com\/https:\/\/twitter.com\/OAziegbe"],"url":"https:\/\/www.javacodegeeks.com\/author\/omozegie-aziegbe"}]}},"_links":{"self":[{"href":"https:\/\/www.javacodegeeks.com\/wp-json\/wp\/v2\/posts\/138788","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.javacodegeeks.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.javacodegeeks.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.javacodegeeks.com\/wp-json\/wp\/v2\/users\/128888"}],"replies":[{"embeddable":true,"href":"https:\/\/www.javacodegeeks.com\/wp-json\/wp\/v2\/comments?post=138788"}],"version-history":[{"count":0,"href":"https:\/\/www.javacodegeeks.com\/wp-json\/wp\/v2\/posts\/138788\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.javacodegeeks.com\/wp-json\/wp\/v2\/media\/219"}],"wp:attachment":[{"href":"https:\/\/www.javacodegeeks.com\/wp-json\/wp\/v2\/media?parent=138788"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.javacodegeeks.com\/wp-json\/wp\/v2\/categories?post=138788"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.javacodegeeks.com\/wp-json\/wp\/v2\/tags?post=138788"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}