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.4.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.4-py3-none-any.whl (4.3 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: flatten_complex_json-0.0.4.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.4.tar.gz
Algorithm Hash digest
SHA256 27ebf49f335534cb64331c6d0a87ef8c74b23de4ba05ab7e86831c5dd5d7391e
MD5 7907e2ff5f17f3785e936254d7096dc6
BLAKE2b-256 f122adbe7d87b844deead57e2211d6e65b9735795ab2f227e41b492ad94a114b

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for flatten_complex_json-0.0.4-py3-none-any.whl
Algorithm Hash digest
SHA256 60a10beccc56d16b408705cc313df2d6f0080dc60cfb2da8f56bd6247dbdb4c0
MD5 6b49132d3653975f486173a4de481f7d
BLAKE2b-256 72e77678c84e3fa7c1edaf052a99afefb5258469f3b272f0847badfecb2e320a

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