Skip to main content
Join the official 2020 Python Developers SurveyStart the survey!

A package for easy json parse.

Project description

Easy JSON2JSON

Description

A python package for deep JSON translation.

You just need to specify you template to get all data from another JSON to avoid doing that manually in your code.

Install

pip install easy-json2json

Usage example

Case #1 Simple JSON

from easyjson2json import Json2Json

source = {"name": "Test Name"} # source JSON

template = {"first_name": "name"} # this is the structure you want your new JSON be 

translator = Json2Json(template=template, source=source)

result = translator.get_result()       

print(result)

# {'first_name': 'Test Name'}

Case #2 Different structure

from easyjson2json import Json2Json

source = {"name": "Test Name", "address": {"name": "My Street", "number": 23}} # when is not a plain JSON

template = {"first_name": "name", "address_name": ["address", "name"]} # you don't want all that structure 

translator = Json2Json(template=template, source=source)

result = translator.get_result()       

print(result)

# {'first_name': 'Test Name', 'address_name': 'My Street'}

Case #3 From ugly JSON

from easyjson2json import Json2Json

source = {"name": "My Name", "ADDRESS": {"name": "My Street", "number": 23}} # ugly JSON happens 

template = {"name": "name", "address": {"_source": "ADDRESS", "name": "name", "number": "number"}} # you want beautiful JSON

translator = Json2Json(template=template, source=source)

result = translator.get_result()       

print(result)

# {'name': 'My Name', 'address': {'name': 'My Street', 'number': 23}}

Case #4 From List in JSON

from easyjson2json import Json2Json

source = {"name": "My Name", "ADDRESSES": [{"name": "My Street", "number": 23}]} # when you have a list

template = {"name": "name", "addresses": {"_source_": "ADDRESSES", "name": "name", "number": "number"}} # then you get that list beautifuly

translator = Json2Json(template=template, source=source)

result = translator.get_result()       

print(result)

# {'name': 'My Name', 'addresses': [{'name': 'My Street', 'number': 23}]}

Source Code

easyjson2json

Author

2020 brworkit.

License

MIT License.

Project details


Download files

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

Files for easy-json2json, version 0.0.2
Filename, size File type Python version Upload date Hashes
Filename, size easy_json2json-0.0.2-py3-none-any.whl (5.7 kB) File type Wheel Python version py3 Upload date Hashes View
Filename, size easy-json2json-0.0.2.tar.gz (3.9 kB) File type Source Python version None Upload date Hashes View

Supported by

Pingdom Pingdom Monitoring Google Google Object Storage and Download Analytics Sentry Sentry Error logging AWS AWS Cloud computing DataDog DataDog Monitoring Fastly Fastly CDN DigiCert DigiCert EV certificate StatusPage StatusPage Status page