Skip to main content

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


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

json_python_flatten-0.1.3.tar.gz (3.9 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

json_python_flatten-0.1.3-py3-none-any.whl (4.9 kB view details)

Uploaded Python 3

File details

Details for the file json_python_flatten-0.1.3.tar.gz.

File metadata

  • Download URL: json_python_flatten-0.1.3.tar.gz
  • Upload date:
  • Size: 3.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.2.0 pkginfo/1.5.0.1 requests/2.24.0 setuptools/49.6.0 requests-toolbelt/0.9.1 tqdm/4.48.2 CPython/3.6.8

File hashes

Hashes for json_python_flatten-0.1.3.tar.gz
Algorithm Hash digest
SHA256 9cb78d4f37e12b5a6b86aa3a0b30c0fa0a8bc3a2ea516a1b178aa4d5fc2ff467
MD5 5b0b1640d398b9564c9417463ca3756a
BLAKE2b-256 7f83a039fdf132b6e2548826ae3ef5579bdeee9dd3e017d1320fe20bc03445f5

See more details on using hashes here.

File details

Details for the file json_python_flatten-0.1.3-py3-none-any.whl.

File metadata

  • Download URL: json_python_flatten-0.1.3-py3-none-any.whl
  • Upload date:
  • Size: 4.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.2.0 pkginfo/1.5.0.1 requests/2.24.0 setuptools/49.6.0 requests-toolbelt/0.9.1 tqdm/4.48.2 CPython/3.6.8

File hashes

Hashes for json_python_flatten-0.1.3-py3-none-any.whl
Algorithm Hash digest
SHA256 297cfda98b19d937c93941cf66cf9e5245af45f222fa4a910d86ebaf58421bfa
MD5 3ac816ef3c9d6acd7e6b79658d73dcfe
BLAKE2b-256 5c309e312b12b6e09f7fdfc76c19773ac4c76307b1e6ed6e1fd44c425344e08a

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page