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.1.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | 106ff6fea4abcddef416bb0ec859980a6c387f099d75e9a09720a1b95dbfdfb4 |
|
MD5 | cf15e23c1883a4fdaef2b92fcafaad5c |
|
BLAKE2b-256 | d51f4df3ebd2ac582bc60d78ebcde225059b664cb0e34258f9fbebe02779843c |
Close
Hashes for json_python_flatten-0.1.1-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | ecc89b7922e86ab46ade97eec357d6a25d952fc82078db60f1b50506a944afad |
|
MD5 | 626f2880bbceb4024e6f0e929fa0110f |
|
BLAKE2b-256 | 1e79fe45775b1fd70e9c37bd64ee27371cd733d618c6715a681c1d9149ee9c06 |