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
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file nested_json2rel_data-0.0.2.tar.gz.
File metadata
- Download URL: nested_json2rel_data-0.0.2.tar.gz
- Upload date:
- Size: 3.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.3.0 pkginfo/1.7.0 requests/2.25.1 setuptools/52.0.0 requests-toolbelt/0.9.1 tqdm/4.56.0 CPython/3.7.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
e741fadf08ed56d3f22bd24ec84b9cd1cb9ff00a619ebe74aa8d4a1266f575ef
|
|
| MD5 |
0753130bf6a326e203925fd956e0c125
|
|
| BLAKE2b-256 |
30aa6e64c556d983168b5e4deb225e15627d01c1fbd97467b2381228f67ebdce
|
File details
Details for the file nested_json2rel_data-0.0.2-py3-none-any.whl.
File metadata
- Download URL: nested_json2rel_data-0.0.2-py3-none-any.whl
- Upload date:
- Size: 4.5 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.3.0 pkginfo/1.7.0 requests/2.25.1 setuptools/52.0.0 requests-toolbelt/0.9.1 tqdm/4.56.0 CPython/3.7.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
71b4e539c16d931d4f6a641cdc1f546c916ea639a3d1a9970ec1ceed625670d5
|
|
| MD5 |
2de77af4732499a7b6c44e552989f021
|
|
| BLAKE2b-256 |
37e58d1f578ddf1c73ca1686ca813c25ed7fb68e704eb589eb065ddbcade28c9
|