Flatten JSON objects
Project description
json_flatten
Flatten/unflatten the JSON object in python.
Installation
pip install json_flatten
Usages
Flatten
# Input Dict
input_dict = {
"abc": {"a": 24,
"b": {"b1": {"size": 3,
"out": "Nope"},
"size": True}},
"xyz": {"x": {"word": 8}, "y": -1, "z": 26},
"pqr": {"pq": [0, None, 2.0, 3.0],
"r": None}
}
from json_python_flatten import flatten
print(flatten(dictionary=input_dict))
{
"abc[a]":24,
"abc[b][b1][size]":3,
"abc[b][b1][out]":"Nope",
"abc[b][size]":True,
"xyz[x][word]":8,
"xyz[y]":-1,
"xyz[z]":26,
"pqr[pq][0]":0,
"pqr[pq][1]":"None",
"pqr[pq][2]":2.0,
"pqr[pq][3]":3.0,
"pqr[r]":"None"
}
Un-Flatten
json_dict = {
"columns[0][data]":"0",
"columns[0][name]":"",
"columns[0][searchable]":"true",
"columns[0][orderable]":"false",
"columns[0][search][value]":"",
"columns[0][search][regex]":"false",
"order[0][column]":"1",
"order[0][dir]":"asc",
"start":"0",
"length":"13",
"search[value]":"jenkins",
"search[regex]":"false",
"searchPanes[group][0]":"Group 1",
"searchPanes[platform][0]":"Window"
}
from json_python_flatten import unflatten
print(unflatten(json_dict=json_dict))
{
"columns":[
{
"data":"0",
"name":"",
"searchable":"true",
"orderable":"false",
"search":{
"value":"",
"regex":"false"
}
}
],
"order":[
{
"column":"1",
"dir":"asc"
}
],
"start":"0",
"length":"13",
"search":{
"value":"jenkins",
"regex":"false"
},
"searchPanes":{
"group":[
"Group 1"
],
"platform":[
"Window"
]
}
}
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 json_python_flatten-0.1.2.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | ac3eab348edf3022d154040759b5d8b9edafa81c21666500f139200d3df66e37 |
|
MD5 | f7c18e01069b4d35431e4e8c62786a25 |
|
BLAKE2b-256 | a6070ee6b71f818ea37dc8ed87945992117c05bcfdbbdd97443ba94f24d921d8 |
Close
Hashes for json_python_flatten-0.1.2-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | f6e4c7d56578c5559bd2d177aa3d44807050bd78b9057db0c463f0a9eaa71245 |
|
MD5 | 6c96f4a0ae77b237111de6c880b358af |
|
BLAKE2b-256 | b7fa04ce9934523d862f508807632c511924fe18cf5980a90f65449b4489515f |