Package to handle complex jsons.
Project description
managerjson
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"
}
Contribuuting
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.4.tar.gz
(4.7 kB
view hashes)
Built Distribution
Close
Hashes for managerjson-0.1.4-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | c3e0d15f07b0f33a6d8aecbda94a76c4fa61fac72abb3cd0efc328f89cdcc7d2 |
|
MD5 | b3bd936531dce0e5031711a4b8c4365a |
|
BLAKE2b-256 | b69d19e51a75391d6e071c7b34deaf42081ef646269550866724e2772e9e8f33 |