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 hashes)

Uploaded Source

Built Distribution

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

Uploaded Python 3

Supported by

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