Package to flatten json Data
Project description
Json-flattening
Flatten Json to Relational Dataframe
Instructions
- Install
pip install json-flattening
- Parameters
json_data: Input data to be flattend, should be dict or list of dict
list_split_to_many: If the final node list data should be splitted to one to many relation(i.e to multiple rows)
ignore_parent_key: Parent Keys to be ignored should be string or list
- Flatten json
from json_flattening import json_flatten
data = [{
"firstName": "Rack",
"lastName": "Jackon",
"gender": "man",
"age": 24,
"address": {
"streetAddress": "126",
"city": "San Jone",
"state": "CA",
"postalCode": "394221"
},
"phoneNumbers": [
{ "type": "home", "number": "7383627627" }
]
}
{
"firstName": "rock",
"lastName": "Jackon",
"gender": "man",
"age": 24,
"address": {
"streetAddress": "126",
"city": "San Jone",
"postalCode": "394221"
},
"phoneNumbers": [
{ "type": "home", "number": "7383627627" }
]
}]
flatten_data = json_flatten(data)
firstName | lastName | gender | age | address_state | address_streetAddress | address_postalCode | address_city | phoneNumbers_type | phoneNumbers_number |
---|---|---|---|---|---|---|---|---|---|
Rack | Jackon | man | 24 | CA | 126 | 394221 | San Jone | home | 7383627627 |
rock | Jackon | man | 24 | NaN | 126 | 394221 | San Jone | home | 7383627627 |
- With ignore parent Key
flatten_data = json_flatten(data,ignore_parent_key=['phoneNumbers','age'])
firstName | lastName | gender | address_state | address_streetAddress | address_postalCode | address_city |
---|---|---|---|---|---|---|
Rack | Jackon | man | CA | 126 | 394221 | San Jone |
rock | Jackon | man | NaN | 126 | 394221 | San Jone |
Disclaimer : For heavily complex nested json which has combination of both sub json and other type like integer and string
the relation may not work properly for simple nested works perfect
Change Log
1.0.0 (12/4/2022)
- First Release
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
json_flattening-1.0.0.tar.gz
(4.3 kB
view hashes)
Built Distribution
Close
Hashes for json_flattening-1.0.0-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 0fcdd222d0830b3365b2239c6f012b05f7d37f0516d4cf187a78166817185cf9 |
|
MD5 | 24b8685d18dcf80329c5d75202e8f69c |
|
BLAKE2b-256 | 92c6abad65e70e8922d8df06afa1e75430b37e1e6ea37ab9452bf9bedb2009f6 |