Skip to main content

Python Package to flatten the complex json data

Project description

Flatten Nested Complex Json Data with flatten_complex_json Package

The flatten_complex_json package simplifies the process of converting complex JSON data into a structured and easy-to-analyze flat pandas dataframe. It offers a user-friendly function that transforms the complex JSON data into a tabular format, where each row represents a record and each column contains a specific attribute or value. This package is designed to make data analysis and processing tasks more accessible, even for users with limited programming experience. It allows you to extract relevant information from deep within the nested structure, enabling efficient data analysis and visualization.

Flatten very complex json data using flatten_complex_json function:

Example

Consider a list of nested dictionaries containing details about batters and toppings. We can use the flatten_complex_json function to flatten this JSON data structure into a flat table as shown:

Function arguments must be same as specified below.

Parameters Type
Json Data Json data in json format

Example Json Data

json_data=[{
"id": "0001",
"type": "donut",
"name": "Cake",
"ppu": 0.55,
"batters":
    {
        "batter":
            [
                { "id": "1001", "type": "Regular" },
                { "id": "1002", "type": "Chocolate" },
                { "id": "1003", "type": "Blueberry" },
                { "id": "1004", "type": "Devil's Choclate" }
            ]
    },
"topping":
    [
        { "id": "5001", "type": "None" },
        { "id": "5002", "type": "Glazed" },
        { "id": "5005", "type": "Sugar" },
        { "id": "5007", "type": "Powdered Sugar" },
        { "id": "5006", "type": "Chocolate" },
        { "id": "5003", "type": "Chocolate" },
        { "id": "5004", "type": "Maple" }
    ]}]

Flatten the Complex Json Data Into Flat Dataframe

Usage

To use the flatten_complex_json function, import the function and pass in your complex json data as a parameter:

or you can read from your json file as shown below

Specify the file path

file_path = 'testing_json.json'#Path of json file

with open(file_path, encoding="utf8") as file:

    json_data = json.load(file)
from flatten_complex_json import *

flatdf= flatten_complex_json(json_data)

print(flatdf) 

Flattened Dataframe

id name ppu type topping_id topping_type batters_batter_id batters_batter_type
0001 Cake 0.55 donut 5001 None 1001 Regular
0001 Cake 0.55 donut 5001 None 1002 Chocolate
0001 Cake 0.55 donut 5001 None 1003 Blueberry
0001 Cake 0.55 donut 5001 None 1004 Devil's Food
0001 Cake 0.55 donut 5002 Glazed 1001 Regular
0001 Cake 0.55 donut 5002 Glazed 1002 Chocolate
0001 Cake 0.55 donut 5002 Glazed 1003 Blueberry

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

flatten_complex_json-0.0.1.tar.gz (3.9 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

flatten_complex_json-0.0.1-py3-none-any.whl (4.3 kB view details)

Uploaded Python 3

File details

Details for the file flatten_complex_json-0.0.1.tar.gz.

File metadata

  • Download URL: flatten_complex_json-0.0.1.tar.gz
  • Upload date:
  • Size: 3.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.11.0

File hashes

Hashes for flatten_complex_json-0.0.1.tar.gz
Algorithm Hash digest
SHA256 238210d9ed04e775ce05947ee7314638272f47966115279d4b0f9e4e6a556ee8
MD5 8edf65caec414f03d55720dea8a38080
BLAKE2b-256 005e4c8ef32c8e37abd5259e97009ba83f669d17618c2900aa4b0f68c5576b1b

See more details on using hashes here.

File details

Details for the file flatten_complex_json-0.0.1-py3-none-any.whl.

File metadata

File hashes

Hashes for flatten_complex_json-0.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 a5f4c174beb09a067acf22a339e25b697742f5ab7fef91f241e5fa741d178428
MD5 c039b84713c81d029e45cd2df36b2cf6
BLAKE2b-256 364f0dd5212067bf7d4f7033820e037dec22454fc988d511c3c50585f536dee8

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page