Skip to main content

Package to handle complex jsons.

Project description

managerjson

PyPI version codecov

Getting started

From PYPI

❯ pipenv install managerjson

from the source

❯  git clone https://gitlab.com/osstorres/managerjson.git
❯  cd managerjson
❯  python3 setup.py install

How to object

from managerjson import JsonObject

objects = JsonObject(
{
    "id": "0001",
    "type": "donut",
    "name": "Cake",
    "ppu": 0.55,
    "batters": {
        "batter": [
            {"id": "1001", "type": "Regular"},
            {"id": "1002", "type": "Chocolate"},
            {"id": "1003", "type": "Blueberry"},
            {"id": "1004", "type": "Devil's Food"},
        ]
    },
    "topping": [
        {"id": "5001", "type": "None"},
        {"id": "5002", "type": "Glazed"},
        {"id": "5005", "type": "Sugar"},
        {"id": "5007", "type": "Powdered Sugar"},
        {"id": "5006", "type": "Chocolate with Sprinkles"},
        {"id": "5003", "type": "Chocolate"},
        {"id": "5004", "type": "Maple"},
    ],
}
)

You can access

❯  print(objects.id)
❯  0001

❯  print(objects.topping)
❯  [{'id': '5001', 'type': 'None'}, {'id': '5002', 'type': 'Glazed'}, {'id': '5005', 'type': 'Sugar'}, {'id': '5007', 'type': 'Powdered Sugar'}, {'id': '5006', 'type': 'Chocolate with Sprinkles'}, {'id': '5003', 'type': 'Chocolate'}, {'id': '5004', 'type': 'Maple'}]

❯  print(objects.batters.batter)
❯  [{'id': '1001', 'type': 'Regular'}, {'id': '1002', 'type': 'Chocolate'}, {'id': '1003', 'type': 'Blueberry'}, {'id': '1004', 'type': "Devil's Food"}]

❯  print(objects.keys())
❯  dict_keys(['id', 'type', 'name', 'ppu', 'batters', 'topping'])

❯  print(objects.json)
❯  {'id': '0001', 'type': 'donut', 'name': 'Cake', 'ppu': 0.55, 'batters': {'batter': [{'id': '1001', 'type': 'Regular'}, {'id': '1002', 'type': 'Chocolate'}, {'id': '1003', 'type': 'Blueberry'}, {'id': '1004', 'type': "Devil's Food"}]}, 'topping': [{'id': '5001', 'type': 'None'}, {'id': '5002', 'type': 'Glazed'}, {'id': '5005', 'type': 'Sugar'}, {'id': '5007', 'type': 'Powdered Sugar'}, {'id': '5006', 'type': 'Chocolate with Sprinkles'}, {'id': '5003', 'type': 'Chocolate'}, {'id': '5004', 'type': 'Maple'}]}


How to flat

from managerjson import flatjson

flatjson(
{
    "id": "0001",
    "type": "donut",
    "name": "Cake",
    "ppu": 0.55,
    "batters": {
        "batter": [
            {"id": "1001", "type": "Regular"},
            {"id": "1002", "type": "Chocolate"},
            {"id": "1003", "type": "Blueberry"},
            {"id": "1004", "type": "Devil's Food"},
        ]
    },
    "topping": [
        {"id": "5001", "type": "None"},
        {"id": "5002", "type": "Glazed"},
        {"id": "5005", "type": "Sugar"},
        {"id": "5007", "type": "Powdered Sugar"},
        {"id": "5006", "type": "Chocolate with Sprinkles"},
        {"id": "5003", "type": "Chocolate"},
        {"id": "5004", "type": "Maple"},
    ],
}
)

The result

{
    "id": "0001",
    "type": "donut",
    "name": "Cake",
    "ppu": 0.55,
    "batters_batter_0_id": "1001",
    "batters_batter_0_type": "Regular",
    "batters_batter_1_id": "1002",
    "batters_batter_1_type": "Chocolate",
    "batters_batter_2_id": "1003",
    "batters_batter_2_type": "Blueberry",
    "batters_batter_3_id": "1004",
    "batters_batter_3_type": "Devils Food",
    "topping_0_id": "5001",
    "topping_0_type": "None",
    "topping_1_id": "5002",
    "topping_1_type": "Glazed",
    "topping_2_id": "5005",
    "topping_2_type": "Sugar",
    "topping_3_id": "5007",
    "topping_3_type": "Powdered Sugar",
    "topping_4_id": "5006",
    "topping_4_type": "Chocolate with Sprinkles",
    "topping_5_id": "5003",
    "topping_5_type": "Chocolate",
    "topping_6_id": "5004",
    "topping_6_type": "Maple"
}

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

managerjson-0.1.6.tar.gz (4.7 kB view details)

Uploaded Source

Built Distribution

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

managerjson-0.1.6-py3-none-any.whl (6.1 kB view details)

Uploaded Python 3

File details

Details for the file managerjson-0.1.6.tar.gz.

File metadata

  • Download URL: managerjson-0.1.6.tar.gz
  • Upload date:
  • Size: 4.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.6.0 importlib_metadata/4.8.2 pkginfo/1.8.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.7.12

File hashes

Hashes for managerjson-0.1.6.tar.gz
Algorithm Hash digest
SHA256 780d044c002211295b5b1ef3051e3d25f9dd70fea5bda19e05cd14a34a3651a3
MD5 ff3ce470730e23238156231d629a14b8
BLAKE2b-256 e2eaa5e34669b83588c99ed290ea9838bf8abd1f6e52e03718d6df349852d736

See more details on using hashes here.

File details

Details for the file managerjson-0.1.6-py3-none-any.whl.

File metadata

  • Download URL: managerjson-0.1.6-py3-none-any.whl
  • Upload date:
  • Size: 6.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.6.0 importlib_metadata/4.8.2 pkginfo/1.8.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.7.12

File hashes

Hashes for managerjson-0.1.6-py3-none-any.whl
Algorithm Hash digest
SHA256 833331a18479cf821daf8958dcbcedabf6424a659c95cfa6af97e2a60df84a8f
MD5 92145e44c241a4fce09b0d950803c84f
BLAKE2b-256 9220518577e0cb24aeb12404fd7af3a782535ec1d6a8536f97615ffb48289d6b

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