Skip to main content

JSON Tree Parser

Project description

CLI tool to view json tree / structure

  • searches for keys or values
  • filters by keys or values
  • Adding limit for list items and search results
  • Dumping the value for a given tree / path
{"a": 1, "b": {"c": 3}}		# 'root -> b -> c'
{"a": 1, "b": [{"c": 3}]}	# 'root -> b -> [0] -> c'

Start

pip install jsontp
# or
pip install git+https://github.com/ames0k0/jsontp

CLI

CLI tool to view json tree / structure

options:
  -h, --help  show this help message and exit
  -i I        [i]nput filepath
  -o O        [o]utput filepath
  -v [V]      [v]view json tree
  -k K        [k]ey to search
  -t T        [t]ree to `-o` the data from
  -l L        [l]imit stdout
  -il IL      [i]tems [l]imit stdout
  -fk FK      [f]ilter stdout by `key`
  -fv FV      [f]ilter stdout by `value`

Usage Example (CLI)

# View tree / structure with array items limit 1
python -m jsontp -i input.json -v -il 1

# Search for `key` (-k), filter by `key` (-fk)
python -m jsontp -i input.json -k id -fk user

# Search for `key` (-k), filter by `key` (-fk), print the value for `tree`
python -m jsontp -i input.json -k id -fk user -o '*'

# Print the value for `tree` (NOTE: `-o <output_filepath>` - to dump a value)
python -m jsontp -i input.json -t 'root -> props -> ... -> user' -o '*'

Experimental Usage Example (API)

from jsontp import PageDataTree
from jsontp.utils import FileIO
from jsontp.config import Key

input_filepath = 'input.json'
output_filepath = 'output.json'

file_io = FileIO(input_filepath)
file_data = file_io.load()

pdt = PageDataTree(file_data)
pdt_tree = pdt.tree_by_key(key='user', result_to=Key.SAVE)

user_data = pdt.data_by_tree(next(pdt_tree))
file_io.dump(user_data, output_filepath)

License :: MIT

Copyright (c) 2022,2024 ames0k0

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

jsontp-1.1.0.tar.gz (5.5 kB view details)

Uploaded Source

File details

Details for the file jsontp-1.1.0.tar.gz.

File metadata

  • Download URL: jsontp-1.1.0.tar.gz
  • Upload date:
  • Size: 5.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.11.6

File hashes

Hashes for jsontp-1.1.0.tar.gz
Algorithm Hash digest
SHA256 7421d4b06f22a646bfc651612f41c18a626c8e41f0e9c5af5b1cc39a0c263d69
MD5 5538d3567b9e7df3e4c5d437b5672f2d
BLAKE2b-256 24d72fe7e0a2ff03c72f85bf62379bdab716c82c954a9fb0e2b36f2d875a9c90

See more details on using hashes here.

Supported by

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