Skip to main content

Interactively inspect or process JSON/JSONL data from pipe.

Project description

grepjson

Interactive JSON processor with built-in debugger

grepjson is a command-line tool designed to help developers interactively inspect and process JSON/JSONL data. It integrates Python's built-in pdb debugger, allowing you to explore JSON objects in real-time or execute custom Python snippets directly from the command line.

Features

  • Interactive Debugging: Drop into a pdb session to inspect JSON objects interactively.
  • JSONL Support: Process JSON Lines (JSONL) format with ease.
  • Custom Execution: Execute Python code snippets on JSON objects directly from the command line.
  • Cross-Platform: Works on UNIX-like systems and Windows (with some limitations).
  • Pipeline Integration: Seamlessly integrates with Unix pipelines and other CLI tools.

Installation

Install grepjson via pip:

pip install grepjson

Usage

Basic Usage

Parse a JSON file and enter an interactive debug session:

cat data.json | grepjson

In the debug session, access the parsed JSON object as obj:

(Pdb) print(obj['key'])

JSONL Support

Process a JSON Lines file and enter debug mode with all objects available as objs:

cat data.jsonl | grepjson --line

Or use a simple form:

cat data.jsonl | grepjson -l

Execute Code Snippets

Extract specific fields without entering debug mode:

cat data.json | grepjson --exec "print(obj['name'])"

Or use a simple form:

cat data.json | grepjson -x "print(obj['name'])"

Process each JSON object in a JSONL file:

cat data.jsonl | grepjson -l -x "print(obj['id'])"

Print Results

Automatically print the result of a code snippet:

cat data.json | grepjson -x "obj['value']" -p

Examples

Example 1: Interactive Debugging

echo '{"name": "Alice", "age": 30}' | grepjson

In the debug session:

(Pdb) print(obj['name'])
Alice
(Pdb) obj['age'] += 1
(Pdb) print(obj)
{'name': 'Alice', 'age': 31}

Example 2: JSONL Processing

echo -e '{"id": 1}\n{"id": 2}\n{"id": 3}' | grepjson -l -x "print(obj['id'])"

Output:

1
2
3

Example 3: Field Extraction

echo '{"name": "Bob", "details": {"age": 25}}' | grepjson -x "obj['details']['age']" -p

Output:

25

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

grepjson-0.2.2.tar.gz (3.0 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

grepjson-0.2.2-py3-none-any.whl (3.2 kB view details)

Uploaded Python 3

File details

Details for the file grepjson-0.2.2.tar.gz.

File metadata

  • Download URL: grepjson-0.2.2.tar.gz
  • Upload date:
  • Size: 3.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.0.1 CPython/3.8.0

File hashes

Hashes for grepjson-0.2.2.tar.gz
Algorithm Hash digest
SHA256 cfe10610009e166f201b1320066852fa9585f4c7854edfd971087fa5a6f4f0cb
MD5 bb4c3c2e2af3738a7b89d069bfccb697
BLAKE2b-256 545d1c02043c52ff460e851b04901e3d73e3cc27f4bd1de409797ef59a9c2530

See more details on using hashes here.

File details

Details for the file grepjson-0.2.2-py3-none-any.whl.

File metadata

  • Download URL: grepjson-0.2.2-py3-none-any.whl
  • Upload date:
  • Size: 3.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.0.1 CPython/3.8.0

File hashes

Hashes for grepjson-0.2.2-py3-none-any.whl
Algorithm Hash digest
SHA256 90199e173c60f1d864ed2d9e08b61f27c15ef2875b0c7d7592664009e268854c
MD5 bca075dd25790207069cbe4e569f84ca
BLAKE2b-256 4fc375aae72988416d1732050c85cf9233c2a3bb4844cbb92df4514e510023be

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