Skip to content

ladzaretti/jsoncompleter

Repository files navigation

jsoncompleter

Go ReferenceGo Report Card

The jsoncompleter repository includes both the jsoncompleter package and the jr CLI tool, providing a simple way to complete truncated JSON strings.

Read more on pkg.go.dev.

Motivation

Too many times, I encountered issues with truncated JSON entries in JSONL (JSON Lines) log dumps, making debugging with tools like jq and others frustrating.

That's where jr comes in, completing truncated JSON strings to make log analysis easier.

Benefits of jr

Truncated JSON data might still contain useful information, jr ensures that no data is discarded due to truncation.

It marks missing parts with placeholders, making it easy to track what's missing.

Installation

Package jsoncompleter

go get github.com/ladzaretti/jsoncompleter

The jr CLI

Using Go

go install github.com/ladzaretti/jsoncompleter/cmd/jr@latest

Binary releases

Precompiled binaries for various architectures are available on the release page.

Usage

$ jr -h
jr - commandline tool for completing truncated JSON lines.

Usage: jr [options] [strings...]
  -m, --mark            Enable marking of truncated JSON lines
  -p, --placeholder     Set a custom placeholder for marking truncation
  -s, --skip-invalid    Skip invalid JSON strings from output
  -d, --debug           Print the position or line number of skipped invalid JSON strings to stderr

Example:

Without jr

This demonstrates the error when parsing a truncated JSON string, where data after the error is not processed.

This JSONL input has 3 lines: the first and last are valid, the second is truncated.

$ echo -e '{"foo":"bar"}\n{"baz":\n{"qux":null}' | jq -c
{"foo":"bar"}
jq: parse error: Unfinished JSON term at EOF at line 4, column 0

With jr

This will complete the truncated JSON and allow the parsing to proceed.

$ echo -e '{"foo":"bar"}\n{"baz":\n{"qux":null}' | jr -m | jq -c
{"foo":"bar"}
{"baz":"","__TRUNCATION_MARKER__":""}
{"qux":null}

About

A command-line tool for completing truncated JSON.

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Contributors 2

  •  
  •