Skip to content

nlink-jp/json-filter

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

13 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

json-filter

A command-line filter that extracts, validates, prettifies, and repairs JSON from arbitrary text streams — ideal for processing LLM outputs, API responses, and log data.

Features

  • JSON extraction: Identifies and extracts JSON objects or arrays embedded in larger text streams using robust pattern matching
  • Automatic prettification: Formats valid JSON with proper indentation
  • Incomplete JSON recovery: Repairs malformed or truncated JSON by adding missing closing braces and brackets
  • Bypass mode: --bypass passes the original input through to stdout if extraction fails, preventing pipeline interruptions

Installation

Download the latest binary for your platform from the releases page.

Extract and place the binary in your $PATH:

unzip json-filter-<version>-<os>-<arch>.zip
mv json-filter /usr/local/bin/

Usage

json-filter reads from stdin and writes processed JSON to stdout.

<command> | json-filter [flags]

Flags

Flag Description
--bypass Pass original input through if JSON extraction fails
--version Print version information and exit

Examples

Extract and prettify JSON from log output:

echo 'INFO: data: {"id": 1, "name": "Alice"}' | json-filter
# {
#   "id": 1,
#   "name": "Alice"
# }

Repair incomplete JSON:

echo '{"data": {"item": "value"' | json-filter
# {
#   "data": {
#     "item": "value"
#   }
# }

Process a JSON array:

echo '[{"id": 1}, {"id": 2}]' | json-filter
# [
#   {"id": 1},
#   {"id": 2}
# ]

Use with curl:

curl -s https://api.github.com/users/octocat | json-filter

Use --bypass to avoid breaking a pipeline:

some-command | json-filter --bypass | next-command

Building

Requires Go 1.16 or later.

git clone https://github.com/nlink-jp/json-filter.git
cd json-filter
make build        # Build for the current platform → dist/json-filter
make build-all    # Cross-compile for all platforms → dist/json-filter-<os>-<arch>
make package      # Build and create .zip archives → dist/json-filter-<version>-<os>-<arch>.zip
make test         # Run the test suite
make clean        # Remove dist/

Target platforms: linux/amd64, linux/arm64, darwin/amd64, darwin/arm64, windows/amd64.

See Also

About

A command-line tool for robust JSON extraction, validation, and repair, especially useful for processing LLM outputs and log data.

Topics

Resources

License

Stars

Watchers

Forks

Contributors