Skip to main content

Package to Flatten JSON data to relational Dataframe

Project description

Json-flattening

Flatten Json to Relational Dataframe

Instructions

  1. Install
pip install json-flattening
  1. Parameters
json_data: Input data to be flattend, should be dict or list of dict
list_split_to_many: If the final node list data should be splitted to one to many relation(i.e to multiple rows)
ignore_parent_key: Parent Keys to be ignored should be string or list
filter_parent_key: Parent Keys only to be considered should be string or list,if none of key specified is in data,will return empty dataframe
  1. Flatten json
from json_flattening import json_flatten

data = [{
    "firstName": "Rack",
    "lastName": "Jackon",
    "gender": "man",
    "age": 24,
    "address": {
        "streetAddress": "126",
        "city": "San Jone",
        "state": "CA",
        "postalCode": "394221"
    },
    "phoneNumbers": [
        { "type": "home", "number": "7383627627" }
    ]
},
{
    "firstName": "rock",
    "lastName": "Jackon",
    "gender": "man",
    "age": 24,
    "address": {
        "streetAddress": "126",
        "city": "San Jone",
        "postalCode": "394221"
    },
    "phoneNumbers": [
        { "type": "home", "number": "7383627627" }
    ]
}]

flatten_data = json_flatten(data)
firstName lastName gender age address_state address_streetAddress address_postalCode address_city phoneNumbers_type phoneNumbers_number
Rack Jackon man 24 CA 126 394221 San Jone home 7383627627
rock Jackon man 24 NaN 126 394221 San Jone home 7383627627
  1. With ignore parent Key
flatten_data = json_flatten(data,ignore_parent_key=['phoneNumbers','age'])
firstName lastName gender address_state address_streetAddress address_postalCode address_city
Rack Jackon man CA 126 394221 San Jone
rock Jackon man NaN 126 394221 San Jone

Change Log

1.0.0 (12/4/2022)

  • First Release

1.0.1 (12/4/2022)

  • Bug fix for complex nested json
  • Bug fix if key have a null value

1.0.2 (12/4/2022)

  • Updated doc string details

1.0.3 (20/6/2022)

  • Bug fix if the parent and child node have same key name

1.0.4 (15/7/2022)

  • Bug fix if the column name is "id" it was skipping it

1.0.5 (18/7/2022)

  • Added Parameter to consider and filter parent keys and ignore rest

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_flattening-1.0.5.tar.gz (4.5 kB view details)

Uploaded Source

Built Distribution

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

json_flattening-1.0.5-py3-none-any.whl (4.5 kB view details)

Uploaded Python 3

File details

Details for the file json_flattening-1.0.5.tar.gz.

File metadata

  • Download URL: json_flattening-1.0.5.tar.gz
  • Upload date:
  • Size: 4.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.0 CPython/3.8.8

File hashes

Hashes for json_flattening-1.0.5.tar.gz
Algorithm Hash digest
SHA256 8061f910496dcf58fb14cc960cf408bfed65d8eb7af8ae2c0f1a65e5b3d90c0f
MD5 a58f9e08c9519365a1eeac91465f43c8
BLAKE2b-256 84e62a24a9e8ee39b8b0bd51f512b5217f7207fda1700fadf9b9e01c2eec94f9

See more details on using hashes here.

File details

Details for the file json_flattening-1.0.5-py3-none-any.whl.

File metadata

File hashes

Hashes for json_flattening-1.0.5-py3-none-any.whl
Algorithm Hash digest
SHA256 a889cf11fe63cff90a7493b5ef96185b305bb5db08ed440510fda808acce1ffe
MD5 e806ce226ac20a939699483f41d61efb
BLAKE2b-256 87574a41f2096764d35b9d2c2a58ee62406ccc645bdd228fd500185cd53095bd

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