Skip to main content

Describe JSON

https://img.shields.io/pypi/v/describe_json.svg https://img.shields.io/travis/vladiibine/describe_json.svg Documentation Status

Tired of looking at JSON objects that contain long arrays? Fear no more! describe_json displays your JSON, shortening strings and arrays. It can also produce jq paths for you, so you know what part of the JSON object you’re looking at. Check out the examples for the full set of features!

Installation

$ pip install describe_json

Features

This library does 2 things

  • Shortens strings. It also displays their length and a md5 hash, so you can know whether multiple strings are equal

  • Displays the length of arrays, and only 1 element, as an example. If arrays have differing elements, too bad, it only displays one element, so you’ll never know what the others look like. You can use the -r flag, to get a random array element though.

Usage

First of all, the tool plays really nicely with jq. Use jq to format the output of describe_json

$ describe_json '{"my": ["json", "object"]}'|jq .
{
  "my": [
    "length: 2; example:",
    "json"
  ]
}

Outputting jq full paths for later inspection

If you took a look at your JSON, and found the data you were looking for, but getting to it with jq will now require a lot of incremental approaches such as the following, you might as well just make describe_json help you with that. It can automatically calculate the jq path, so you don’t have to scroll up anymore!

$ echo '{"a": {"b": [{"c": 1}]}}' | jq '.a'
$ echo '{"a": {"b": [{"c": 1}]}}' | jq '.a.b'
$ echo '{"a": {"b": [{"c": 1}]}}' | jq '.a.b[0]'
$ echo '{"a": {"b": [{"c": 1}]}}' | jq '.a.b[0].c'

Instead of the above, just use the -j flag, and you’ll see full paths for all dict keys

$ describe_json '{"a": {"b": [{"c": 1}]}}' -j
{'.a': {'.a.b': [{'.a.b[0].c': 1}]}}

Basic piping

$ echo '{"a": [1, 2, 3, 4]}' | describe_json
{"a": ["length: 4; example:", 1]}

Basic array shortening

$ describe_json '{"a": [1, 2, 3, 4]}'
{"a": ["length: 4; example:", 1]}

Do you have some super long strings?

$ describe_json '{"key": "suuuuuuuuuuuuuper long string"}'
{"key": "suuuuuuuuu... len: 29, md5: b7d562a2bcec0a8a346b5f32c59f257f"}

…ok, in this case the output is longer than the string. But you’ll be happier when the string is 50K long

Use a .json file

$ cat example.json
{"key1": ["a", "b", "c"]}
$ describe_json -f example.json
{"key1": ["length: 3; example:", "a"]}

Use a random array element

By default, the first element of an array is displayed. Use a random one?

$ describe_json -r {"key1": ["a", "b", "c"]}
{"key1": ["length: 3; example:", "b"]}

Specify a maximum array length

By default, only one element is displayed from an array. Specify the maximum size of arrays, after which, they are displayed as shortened

$ describe_json -a 3 '{"key1": ["a", "b", "c"]}'
{"key1": ["a", "b", "c"]}

Specify a maximum string length

By default, strings longer than 10 characters are truncated, and their md5 hash is shown (so you can see whether multiple strings that begin with the same characters are equal or not). Specify a maximum length for strings

$ describe_json -s 30 '{"key": "qwertyuiopasdfghjklzxcvbnm"}
{"key": "qwertyuiopasdfghjklzxcvbnm"}

and that’s about it! :)

Testing it in development mode

There are only doctests for the moment. They will be ran as 1 unit test, but don’t worry, there are more than just 1 test.

$ python setup.py test

Credits

This package was created with Cookiecutter and the audreyr/cookiecutter-pypackage project template.

History

0.1.0 (2019-03-31)

  • First release on PyPI.

Metadata

Release files for describe-json 0.1.7

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for describe-json 0.1.7
File Size Uploaded Provenance Actions
describe_json-0.1.7.tar.gz 13.0 kB Without provenance Details for describe_json-0.1.7.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for describe-json 0.1.7
File Interpreter ABI Platform Actions
describe_json-0.1.7-py2.py3-none-any.whl Python 2, Python 3 none any Details for describe_json-0.1.7-py2.py3-none-any.whl

Total release size: 20.8 kB

Release files / describe_json-0.1.7.tar.gz

Download URL describe_json-0.1.7.tar.gz
Size 13.0 kB
Tags Source
SHA-256 checksum
How to use checksums
30db41b7615def1cf8302926393cc93015ebdbc978d09ffcf88e537802f81485
BLAKE2b-256 checksum
How to use checksums
6cd7613705e09bc58c49299183bb68c54aab81616c22c92dca2d5e50add6e5b4
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.4.2 importlib_metadata/4.8.1 pkginfo/1.7.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.2 CPython/3.9.6

Release files / describe_json-0.1.7-py2.py3-none-any.whl

Download URL describe_json-0.1.7-py2.py3-none-any.whl
Size 7.8 kB
Tags Python 2 Python 3
SHA-256 checksum
How to use checksums
f6fc3a06bf4044cda009306a3fc7bcea897acd282638163c9807ddcc15268f36
BLAKE2b-256 checksum
How to use checksums
a3d96b195fcaab3856670740134a2f40c0442e262648e3e462dd7bcea5a73557
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.4.2 importlib_metadata/4.8.1 pkginfo/1.7.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.2 CPython/3.9.6

Security for describe-json 0.1.7

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.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page