Skip to main content

Extract the leaves from a JSON file and show the paths to said leaves

Project description

json-leaves

@readwithai - X - blog - machine-aided reading - 📖⚡️🖋️

Turn a JSON object into path-value pairs suitable for grepping.

JSON is quite nice but digging through JSON can be a pain - as can building queries to fetch the values you have found. json-leaves allows you to use grep and other command-line tools to find what you want and then gives you a selector (suitable for use in other tools like python or jq so that you can programmatically do the same thing).

Alternatives and prior work

I could not quickly find a command-line tool to the same thing. I found a recipe for jq but this sufficiently unwieldy that I do not want to use it - though it could be placed in a script that you place on your path. I wanted to make something reusable on any machine.

More generally, any use of this tools likely wants to be aware of the jq tool which provides a DSL to perform many JSON operations from the command-line.

This tool is somewhat related to GenSON which will return the schema of JSON data in that it helps you understand unknown JSON data. The author wrote short-schema some years ago which renders the output from GenSON easily readable.

Those who are incapable of using the command-line and used to spending their lives clicking because they are too lazy to learn anything, may well use JSON browsers such as those in VSCode or browsers. Or you may simply prefer these tools.

Installation

You can install json-leaves using pipx:

pipx install json-leaves

Usage

This fetches data related to the pip installations of the kitty-plotnine package and then unpacks all leaves and values.

curl https://pypistats.org/api/packages/kitty-plotnine/python_major | json-leaves

If you want to show just the values you can use:

curl https://pypistats.org/api/packages/kitty-plotnine/python_major | json-leaves

To distinguish between strings and integers (or nulls) --quote (or -q).

curl https://pypistats.org/api/packages/kitty-plotnine/python_major | json-leaves -q

You can also output JSON data with --json and include nodes as well as leaves with --nodes

About me

I am @readwithai. I create tools for reading, research and agency sometimes using the markdown editor Obsidian.

I also create a stream of tools that are related to carrying out my work.

I write about lots of things - including tools like this - on X. My blog is more about reading and research and agency.

@readwithai logo

Project details


Download files

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

Source Distribution

json-leaves-1.1.0.tar.gz (3.7 kB view details)

Uploaded Source

File details

Details for the file json-leaves-1.1.0.tar.gz.

File metadata

  • Download URL: json-leaves-1.1.0.tar.gz
  • Upload date:
  • Size: 3.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.0.0 CPython/3.12.3

File hashes

Hashes for json-leaves-1.1.0.tar.gz
Algorithm Hash digest
SHA256 dba8d617d9e804fee79992d2b5b57b0bef73f955396b3fa8eb31972b1c15f320
MD5 124e991538f2c46b29bb44d633f96a4a
BLAKE2b-256 d19c1d085b85ec09e56bdba0cc2250e73379e422f49e30619a48a7de1f3e19ff

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page