Json shorthand for python
Project description
# J
Python shorthand for json. inspired by [q](https://pypi.org/project/q/)
This package allows json load, dump from and to file with few code.
## Installation
```bash
pip install jshort
```
## Usage
```python
import j #This is an instance
# loads json from file, stores it in data property
h = j(input_path='/tmp/data.json')
# get data
h.data
#{"foo": "bar"}
# Display colored content
print(h)
# or
h.prt()
{
"foo": "bar"
}
# The same, in short
j(i='/tmp/data.json').d
j(i='/tmp/data.json').prt()
# Write json
j(output_path='/tmp/data.json', data={"foo": "bar"})
# Also change print indnentation
h = j(o='/tmp/data.json', data={"hey": "jude"}, indent=2)
h.prt()
{
"hey": "jude"
}
# Traversing json documents using https://pypi.org/project/jsonpath-ng/
j(d=my_dict).path('key')
# Shorter and with more filtering
j(d=my_dict).p('sub.*')
# Or with an array and from a file
j(i='/tmp/data.json').p('key[1]')
```
Enjoy.
Have a look at https://pypi.org/project/jsonpath-ng/ for more about json traversing
Python shorthand for json. inspired by [q](https://pypi.org/project/q/)
This package allows json load, dump from and to file with few code.
## Installation
```bash
pip install jshort
```
## Usage
```python
import j #This is an instance
# loads json from file, stores it in data property
h = j(input_path='/tmp/data.json')
# get data
h.data
#{"foo": "bar"}
# Display colored content
print(h)
# or
h.prt()
{
"foo": "bar"
}
# The same, in short
j(i='/tmp/data.json').d
j(i='/tmp/data.json').prt()
# Write json
j(output_path='/tmp/data.json', data={"foo": "bar"})
# Also change print indnentation
h = j(o='/tmp/data.json', data={"hey": "jude"}, indent=2)
h.prt()
{
"hey": "jude"
}
# Traversing json documents using https://pypi.org/project/jsonpath-ng/
j(d=my_dict).path('key')
# Shorter and with more filtering
j(d=my_dict).p('sub.*')
# Or with an array and from a file
j(i='/tmp/data.json').p('key[1]')
```
Enjoy.
Have a look at https://pypi.org/project/jsonpath-ng/ for more about json traversing
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 Distribution
jshort-1.0.1.tar.gz
(1.9 kB
view hashes)
Built Distribution
Close
Hashes for jshort-1.0.1-py2.py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | b7a3a19bb7f6392d98292988a1e9a09072f49bde64ca70ecfa576997f4afb779 |
|
MD5 | 7a05f0aa4b2fb6bf65c43271f258e6d6 |
|
BLAKE2b-256 | 8d52f93067d8b78d3d8e61420052f4586dcb3ae68c9d9153e5b02b60ec6f9aa5 |