Jshort
Python shorthand for json. inspired by q
This package allows json load, dump from and to file with few code.
Installation
pip install jshort
Usage
# This is an instance
import j
# 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()
# {
# "oh": "dayum!"
# }
# The same, in short
# For data
j(i='/tmp/data.json').d
# Print
j(i='/tmp/data.json').prt()
# Write json
j(output_path='/tmp/out.json', data={"foo": "bar"})
# Also write data in a shorter way and change print content setting indentation to 2
j(o='/tmp/out.json', d={"hey": "jude"}, indent=2).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 fintering on an array and from a file
j(i='/tmp/data.json').p('key[1]')
Have a look at https://pypi.org/project/jsonpath-ng/ for more about json traversing.
If only one result is returned from filtering, the path method returns only the result otherwise it is a list of results.
Json as object
It is possible to manipulate json in j instance as a python object. Try the following:
o = j(d={'a': {'b': 1}}).obj
#raw data
o.data_
#{'a': {'b': 1}}
#pretty print it
print(o)
#dumps with syntax coloration the json content
o.c
#None
o.a
#{'b': 1}
o.a.b
#1
o.a['test'] = 1
print(o.d_)
#{'a': {'b': 1}, 'test': 1}
Enjoy.
Metadata
Release files for jshort 1.1.2
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| jshort-1.1.2.tar.gz | 3.8 kB | Without provenance | Details for jshort-1.1.2.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| jshort-1.1.2-py2.py3-none-any.whl | Python 3, Python 2 | none | any | Details for jshort-1.1.2-py2.py3-none-any.whl |
Total release size: 7.6 kB
Release files / jshort-1.1.2.tar.gz
| Download URL | jshort-1.1.2.tar.gz |
|---|---|
| Size | 3.8 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
fd50f90c4dd3c37af80d8c09f10925073999326aac1df89798b4e55820cd5273
|
|
BLAKE2b-256 checksum How to use checksums |
a8a9d8590c65d2a7600641cd30eff32392beb07b6930ba55991c678db1fac4b9
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/1.13.0 pkginfo/1.5.0.1 requests/2.21.0 setuptools/41.0.1 requests-toolbelt/0.9.1 tqdm/4.31.1 CPython/3.6.8
|
Release files / jshort-1.1.2-py2.py3-none-any.whl
| Download URL | jshort-1.1.2-py2.py3-none-any.whl |
|---|---|
| Size | 3.8 kB |
| Tags | Python 2 Python 3 |
|
SHA-256 checksum How to use checksums |
e09a599bc0ed9beb8f0ccb75cff39a0ef7e1e1b0a158808b5e26afd59db688a5
|
|
BLAKE2b-256 checksum How to use checksums |
a92da4bed131dd046ca00d182b71efac1d961753c67c257c285687b257a374b9
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/1.13.0 pkginfo/1.5.0.1 requests/2.21.0 setuptools/41.0.1 requests-toolbelt/0.9.1 tqdm/4.31.1 CPython/3.6.8
|
Security for jshort 1.1.2
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.