flatten-complex-json


Nameflatten-complex-json JSON
Version 0.0.4 PyPI version JSON
download
home_page
SummaryPython Package to flatten the complex json data
upload_time2023-11-29 15:23:48
maintainer
docs_urlNone
authorabhishek
requires_python
license
keywords flatten json flatten api data flat json data python flatten dataframe abhishek aggarwal
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # 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)

```python

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|

            

Raw data

            {
    "_id": null,
    "home_page": "",
    "name": "flatten-complex-json",
    "maintainer": "",
    "docs_url": null,
    "requires_python": "",
    "maintainer_email": "",
    "keywords": "flatten json,flatten api data,flat json data,python flatten dataframe,abhishek aggarwal",
    "author": "abhishek",
    "author_email": "abhishekaggarwal1211@gmail.com",
    "download_url": "https://files.pythonhosted.org/packages/f1/22/adbe7d87b844deead57e2211d6e65b9735795ab2f227e41b492ad94a114b/flatten_complex_json-0.0.4.tar.gz",
    "platform": null,
    "description": "# Flatten Nested Complex Json Data with flatten_complex_json Package\r\n\r\nThe 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. \r\n\r\n#  Flatten very complex json data using flatten_complex_json function:\r\n\r\n## Example\r\nConsider 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:\r\n\r\n# Function arguments must be same as specified below.\r\n\r\n| Parameters| Type| \r\n| :-------- | :------- | \r\n| Json Data | Json data in json format |\r\n\r\n# Example Json Data \r\n \r\n    json_data=[{\r\n    \"id\": \"0001\",\r\n    \"type\": \"donut\",\r\n    \"name\": \"Cake\",\r\n    \"ppu\": 0.55,\r\n    \"batters\":\r\n        {\r\n            \"batter\":\r\n                [\r\n                    { \"id\": \"1001\", \"type\": \"Regular\" },\r\n                    { \"id\": \"1002\", \"type\": \"Chocolate\" },\r\n                    { \"id\": \"1003\", \"type\": \"Blueberry\" },\r\n                    { \"id\": \"1004\", \"type\": \"Devil's Choclate\" }\r\n                ]\r\n        },\r\n    \"topping\":\r\n        [\r\n            { \"id\": \"5001\", \"type\": \"None\" },\r\n            { \"id\": \"5002\", \"type\": \"Glazed\" },\r\n            { \"id\": \"5005\", \"type\": \"Sugar\" },\r\n            { \"id\": \"5007\", \"type\": \"Powdered Sugar\" },\r\n            { \"id\": \"5006\", \"type\": \"Chocolate\" },\r\n            { \"id\": \"5003\", \"type\": \"Chocolate\" },\r\n            { \"id\": \"5004\", \"type\": \"Maple\" }\r\n        ]}]\r\n\r\n# Flatten the Complex Json Data Into Flat Dataframe\r\n## Usage\r\nTo use the flatten_complex_json function, import the function and pass in your complex json data as a parameter:\r\n\r\nor you can read from your json file as shown below\r\n\r\n## Specify the file path\r\n\r\nfile_path = 'testing_json.json'#Path of json file\r\n \r\n\r\n    with open(file_path, encoding=\"utf8\") as file:\r\n\r\n        json_data = json.load(file)\r\n\r\n```python\r\n\r\nfrom flatten_complex_json import *\r\n\r\nflatdf= flatten_complex_json(json_data)\r\n\r\nprint(flatdf) \r\n```\r\n\r\n## Flattened Dataframe\r\n| id| name| ppu | type | topping_id | topping_type               | batters_batter_id | batters_batter_type               |\r\n| :-------- | :------- | :------------------------- |:-------- | :------- | :------------------------- |:-------- | :------- |\r\n|0001|Cake|0.55|donut| 5001| None| 1001| Regular|\r\n|0001|Cake|0.55|donut| 5001| None| 1002| Chocolate|\r\n|0001|Cake|0.55|donut| 5001| None| 1003| Blueberry|\r\n|0001|Cake|0.55|donut| 5001| None| 1004| Devil's Food|\r\n|0001|Cake|0.55|donut| 5002| Glazed| 1001| Regular|\r\n|0001|Cake|0.55|donut| 5002| Glazed| 1002| Chocolate|\r\n|0001|Cake|0.55|donut| 5002| Glazed| 1003| Blueberry|\r\n",
    "bugtrack_url": null,
    "license": "",
    "summary": "Python Package to flatten the complex json data",
    "version": "0.0.4",
    "project_urls": null,
    "split_keywords": [
        "flatten json",
        "flatten api data",
        "flat json data",
        "python flatten dataframe",
        "abhishek aggarwal"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "72e77678c84e3fa7c1edaf052a99afefb5258469f3b272f0847badfecb2e320a",
                "md5": "6b49132d3653975f486173a4de481f7d",
                "sha256": "60a10beccc56d16b408705cc313df2d6f0080dc60cfb2da8f56bd6247dbdb4c0"
            },
            "downloads": -1,
            "filename": "flatten_complex_json-0.0.4-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "6b49132d3653975f486173a4de481f7d",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": null,
            "size": 4256,
            "upload_time": "2023-11-29T15:23:45",
            "upload_time_iso_8601": "2023-11-29T15:23:45.858379Z",
            "url": "https://files.pythonhosted.org/packages/72/e7/7678c84e3fa7c1edaf052a99afefb5258469f3b272f0847badfecb2e320a/flatten_complex_json-0.0.4-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "f122adbe7d87b844deead57e2211d6e65b9735795ab2f227e41b492ad94a114b",
                "md5": "7907e2ff5f17f3785e936254d7096dc6",
                "sha256": "27ebf49f335534cb64331c6d0a87ef8c74b23de4ba05ab7e86831c5dd5d7391e"
            },
            "downloads": -1,
            "filename": "flatten_complex_json-0.0.4.tar.gz",
            "has_sig": false,
            "md5_digest": "7907e2ff5f17f3785e936254d7096dc6",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": null,
            "size": 3874,
            "upload_time": "2023-11-29T15:23:48",
            "upload_time_iso_8601": "2023-11-29T15:23:48.442413Z",
            "url": "https://files.pythonhosted.org/packages/f1/22/adbe7d87b844deead57e2211d6e65b9735795ab2f227e41b492ad94a114b/flatten_complex_json-0.0.4.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2023-11-29 15:23:48",
    "github": false,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "lcname": "flatten-complex-json"
}
        
Elapsed time: 0.19638s