package to convert nested json to relational and flat data structure.
Project description
Description
This package accepts a nested json as input parameter and provides a flat structured json as output. The output data has additional attributes that help maintaining the relational integrity of the data with parent and child.
Installation
pip install nested-json2rel-data
Usage example
-
json file : json_data.json
{
"name": "Peter Parker",
"job" : "developer",
"organization": "Daily Bugle",
"address":{"country":"Scotland",
"state":"Wishaw",
"city":"Glasgow",
"pin":"BA1 2FJ"
},
"email":["peter.parker@gmail.com"
,"peter_parker@yahoo.com",
{"primary":"peter.parker@microsoft.com"
,"secondary":"peter.parker@ibm.com"}],
"education":[
{"degree": "Bachelor in Media",
"university":"MIT",
"school name":"MIT",
"contact no":[1,2]
},
{"degree":"Media and Journalism",
"university":"oxford",
"school":"Oxford",
"contact no":[3,4]
},
{"degree":"Social Science",
"university":"Cambridge",
"school":"Cambridge",
"contact no":[5,6]
}
],
"other":{"dob":"10-08-2001",
"parent":{"mother":"Mary Parker",
"father":"Richard Parker",
"brother":"Harry Osborn",
"gardian":{"primary":"self",
"secondary":"mother"},
"grandie":{"Uncle":"Ben Parker",
"auntie" : "Mary Parker"}
},
"birth place": "20 Ingram",
"interest":["football","painting","photography","DIY"]
},
"social":{"facebook":"yes",
"instagram":"yes",
"twitter":"no"
}
}
-
read_json.py
import json
from nested_json2rel_data import nested_json_parser as njp
with open('json_data.json') as json_file:
data = json.load(json_file)
p = njp.nested_json_parser(data)
d=p.bucket()
print("*************dict :")
print(d)
-
output
*************dict :
[{'root_id': 4, 'root_name': 'address', 'child_of': 'root', 'child_of_id': 0, 'country': 'Scotland', 'state': 'Wishaw', 'city': 'Glasgow', 'pin': 'BA1 2FJ'}, {'root_id': 2, 'root_name': 'email', 'child_of': 'root', 'child_of_id': 0, 'email': 'peter.parker@gmail.com'}, {'root_id': 3, 'root_name': 'email', 'child_of': 'root', 'child_of_id': 0, 'email': 'peter_parker@yahoo.com'}, {'root_id': 12, 'root_name': 'email', 'child_of': 'root', 'child_of_id': 0, 'primary': 'peter.parker@microsoft.com', 'secondary': 'peter.parker@ibm.com'}, {'root_id': 5, 'root_name': 'contact no', 'child_of': 'education', 'child_of_id': 12, 'contact no': 1}, {'root_id': 6, 'root_name': 'contact no', 'child_of': 'education', 'child_of_id': 12, 'contact no': 2}, {'root_id': 12, 'root_name': 'education', 'child_of': 'root', 'child_of_id': 0, 'degree': 'Bachelor in Media', 'university': 'MIT', 'school name': 'MIT'}, {'root_id': 6, 'root_name': 'contact no', 'child_of': 'education', 'child_of_id': 13, 'contact no': 3}, {'root_id': 7, 'root_name': 'contact no', 'child_of': 'education', 'child_of_id': 13, 'contact no': 4}, {'root_id': 13, 'root_name': 'education', 'child_of': 'root', 'child_of_id': 0, 'degree': 'Media and Journalism', 'university': 'oxford', 'school': 'Oxford'}, {'root_id': 7, 'root_name': 'contact no', 'child_of': 'education', 'child_of_id': 15, 'contact no': 5}, {'root_id': 8, 'root_name': 'contact no', 'child_of': 'education', 'child_of_id': 15, 'contact no': 6}, {'root_id': 15, 'root_name': 'education', 'child_of': 'root', 'child_of_id': 0, 'degree': 'Social Science', 'university': 'Cambridge', 'school': 'Cambridge'}, {'root_id': 31, 'root_name': 'gardian', 'child_of': 'parent', 'child_of_id': 27, 'primary': 'self', 'secondary': 'mother'}, {'root_id': 34, 'root_name': 'grandie', 'child_of': 'parent', 'child_of_id': 27, 'Uncle': 'Ben Parker', 'auntie': 'Mary Parker'}, {'root_id': 27, 'root_name': 'parent', 'child_of': 'other', 'child_of_id': 25, 'mother': 'Mary Parker', 'father': 'Richard Parker', 'brother': 'Harry Osborn'}, {'root_id': 5, 'root_name': 'interest', 'child_of': 'other', 'child_of_id': 25, 'interest': 'football'}, {'root_id': 6, 'root_name': 'interest', 'child_of': 'other', 'child_of_id': 25, 'interest': 'painting'}, {'root_id': 7, 'root_name': 'interest', 'child_of': 'other', 'child_of_id': 25, 'interest': 'photography'}, {'root_id': 8, 'root_name': 'interest', 'child_of': 'other', 'child_of_id': 25, 'interest': 'DIY'}, {'root_id': 25, 'root_name': 'other', 'child_of': 'root', 'child_of_id': 0, 'dob': '10-08-2001', 'birth place': '20 Ingram'}, {'root_id': 39, 'root_name': 'social', 'child_of': 'root', 'child_of_id': 0, 'facebook': 'yes', 'instagram': 'yes', 'twitter': 'no'}, {'root_id': 0, 'root_name': 'root', 'child_of': 'root', 'child_of_id': 0, 'name': 'Peter Parker', 'job': 'developer', 'organization': 'Daily Bugle'}]
Definitions
Attribute | Parameter | Description |
---|---|---|
nested_json_parser.nested_json_parser(data) | data | Json data |
p.bucket() | None | not required |
Source code
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Close
Hashes for nested_json2rel_data-0.0.2.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | e741fadf08ed56d3f22bd24ec84b9cd1cb9ff00a619ebe74aa8d4a1266f575ef |
|
MD5 | 0753130bf6a326e203925fd956e0c125 |
|
BLAKE2b-256 | 30aa6e64c556d983168b5e4deb225e15627d01c1fbd97467b2381228f67ebdce |
Close
Hashes for nested_json2rel_data-0.0.2-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 71b4e539c16d931d4f6a641cdc1f546c916ea639a3d1a9970ec1ceed625670d5 |
|
MD5 | 2de77af4732499a7b6c44e552989f021 |
|
BLAKE2b-256 | 37e58d1f578ddf1c73ca1686ca813c25ed7fb68e704eb589eb065ddbcade28c9 |