Save time while parsing json or dictionary object in python.
Project description
# python-jsonparser
This package will help you to reduce your stress while parsing json in python. Follow the steps below for using python-jsonparser
Install the package from pypi
pip install python-jsonparser
Now let’s assume we have a json object as below.
- dummy = {
“name”: { “first_name”: “ABC”, “last_name”: “EFG” }, “details”: { “phone”:[“xxxxxxxxx”, “00xxxxxxx”, “0000000000”] } }
3. Now assume we want first_name, last_name and only first phone number from the list. For this create a class TestClass as below and inherit JSONParser from :
from json_parser import JSONParser
- class TestClass(JSONParser):
first_name = ‘name/first_name’ last_name = ‘name/last_name’ phone = ‘details/$1’
Create instance of your class and pass the json object.
test_obj = TestClass(dummy)
Now call the validate method from the object created.
output = test_obj.validate()
You will have following as the output:
{ ‘first_name’: ‘ABC’, ‘last_name’: ‘EFG’, ‘phone’: ‘00xxxxxxx’ }
For getting the range of elements from the list you can use $x:$y
from json_parser import JSONParser
- class TestClass(JSONParser):
first_name = ‘name/first_name’ last_name = ‘name/last_name’ phone = ‘details/$1:$3’
- Output:
{ ‘first_name’: ‘ABC’, ‘last_name’: ‘EFG’, ‘phone’: [‘00xxxxxxx’, ‘0000000000’] }
8. This was all about single object. What if you have json list of objects. In that case set many=True while creating the instance of your class.
For example:
test_obj = TestClass(dummy, many=True)
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distributions
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file python_jsonparser-1.0-py3-none-any.whl.
File metadata
- Download URL: python_jsonparser-1.0-py3-none-any.whl
- Upload date:
- Size: 1.8 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.4.1 importlib_metadata/4.0.1 pkginfo/1.7.0 requests/2.22.0 requests-toolbelt/0.9.1 tqdm/4.60.0 CPython/3.8.5
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
f1885446da3e27dd908aa8fcc29f171cbcafcb646603f9a288518d559320cc8f
|
|
| MD5 |
1dfe6a6ac615d974e4d0be78c9ecc7a2
|
|
| BLAKE2b-256 |
7e9bebcd4bc8e38af77ed713b66e45a81835996d2d8f4c2cd8212036866f2c1a
|