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.1.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.1-py3-none-any.whl (3.2 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: grepjson-0.2.1.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.1.tar.gz
Algorithm Hash digest
SHA256 9b8c94d88504115779f957cd6f486b70edf152c8ca0dc17883823a102239a0e2
MD5 4366d1fd592a263ced071ba5e08a88a4
BLAKE2b-256 d3d047ba6e03a0b3e7bb329177da2415a6127e1daa787acae27ad424bf909e75

See more details on using hashes here.

File details

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

File metadata

  • Download URL: grepjson-0.2.1-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.1-py3-none-any.whl
Algorithm Hash digest
SHA256 1c52bfee9b3bdfe69531ba5b774e49eecb0f93109ea9eb55f5c2bd847b15e525
MD5 426519d17ef7130dff1e335db3f45f39
BLAKE2b-256 ed6f194805ba6ba05b71d64122a08d15556ad129b5e08df653528c210456aff5

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