VOOZH about

URL: https://www.geeksforgeeks.org/python/extract-nested-data-from-complex-json/

⇱ Extract Nested Data From Complex Json - GeeksforGeeks


  • Courses
  • Tutorials
  • Interview Prep

Extract Nested Data From Complex Json

Last Updated : 23 Jul, 2025

JSON (JavaScript Object Notation) is a widely used data interchange format due to its simplicity and human-readable structure. In many scenarios, JSON data can be complex, containing nested structures and arrays. Extracting specific information from such complex JSON becomes essential for data analysis, integration, and various programming tasks. In this article, we will explore methods to efficiently extract nested data from complex JSON in Python.

JSON Data

In this article, we have used the following complex JSON and we will extract nested data from this by using different approaches.

Python Extract Nested Data From Complex Json

Below are some of the ways by which we can extract nested data from complex JSON in Python:

  1. Using dot Notation
  2. Using List Comprehension
  3. Using Recursion

Using dot Notation

In this approach, we directly access the nested elements by chaining the keys using dot notation. For instance, data["location"]["country"] retrieves the country value.


Output
Extracted Data using Dot Notation:
Country: India
City: Greater Noida

Using List Comprehension

List comprehension is employed here to filter and extract specific nested data. For example, it gathers educational departments for the organization "GeeksforGeeks" and completed projects.


Output
Extracted Data using List Comprehension:
Educational Departments: ['Computer Science', 'Mathematics', 'Physics']
Completed Projects: ['ProjectX', 'ProjectY']

Using Recursion

A recursive function is utilized to traverse nested structures dynamically. The function extract_data_recursive takes a list of keys and retrieves the nested data accordingly. In this case, it extracts the first department of the first organization.


Output
Extracted Data using Recursion:
Educational Department (Recursive): Computer Science
Comment