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.3.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | 9cb78d4f37e12b5a6b86aa3a0b30c0fa0a8bc3a2ea516a1b178aa4d5fc2ff467 |
|
MD5 | 5b0b1640d398b9564c9417463ca3756a |
|
BLAKE2b-256 | 7f83a039fdf132b6e2548826ae3ef5579bdeee9dd3e017d1320fe20bc03445f5 |
Close
Hashes for json_python_flatten-0.1.3-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 297cfda98b19d937c93941cf66cf9e5245af45f222fa4a910d86ebaf58421bfa |
|
MD5 | 3ac816ef3c9d6acd7e6b79658d73dcfe |
|
BLAKE2b-256 | 5c309e312b12b6e09f7fdfc76c19773ac4c76307b1e6ed6e1fd44c425344e08a |