jq-live

command module
v0.0.0-...-203dfb9 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 19, 2022 License: MIT Imports: 9 Imported by: 0

README

jq-live

jq is a fantastic tool for working with JSON on the command line, but jq-live makes it easier to explore large payloads with which you're not already familiar.

Add it to your data processing chain when you would normally use jq but don't know what selectors or processors you need yet.

$ jq-live -h
jq-live: on-the-fly JSON processing

Usage: jq-live <program> [path]
  -c    compact output
  -debug string
        path to write debug information
  -r    raw output

keyboard shortcuts:

  Ctrl-E: Toggle expanded or compact results
  Ctrl-R: Toggle raw results
  Ctrl-P: Print current results to stdout and quit
  Ctrl-S: Save current results to specified file and quit

Call jq-live in one of a few ways:

  • Call with a path to a file
    • jq-live something.json
    • jq-live 'keys' something.json
  • Pass JSON through stdin
    • cat $JSON | jq-live
    • jq-live 'keys' < something.json
    • curl -s http://something.com/endpoint.json | jq-live | wc -l

Here's some jq-live in action:

jq-live demo asciicast

Getting jq-live

  • Binary downloads: Not available yet
  • Package managers: Not available yet
  • Via go get
    • Run go get -u github.com/TheDahv/jq-live

Possible Future Features or Changes

Features:

  • In-app keyboard shortcuts display

JSON Processing:

  • Implement jq as library calls rather than shell callouts

UI Features:

Known Issues

  • jq required to be installed on host
  • Only tested on OSX and Linux
  • Occasional input event crashing from Termbox [issue]

Code TODOs:

main.go

  • Support cancellation in save prompt
  • handle "mkdir -p" style directory create
  • need some kind of UI indicator to indicate active options
  • distinguish between normal parse errors and crashable errors

ui/ui.go

  • move exported fields behind methods so we can wrap in an interface

Development

To get started working on jq-live, download the project to your computer with:

go get -u github.com/TheDahv/jq-live

This pulls down the code, its dependencies, and installs a copy of jq-live in $GOPATH/bin.

Modules

This project is also a chance for me to play with Go modules. Go modules require at least Go 1.11. If you have a satisfactory Go installation, activate module mode:

export GO111MODULE=on

In either scenario, run go get -u github.com/TheDahv/jq-live to get package dependencies.

JSON Processing

The json package manages sending data and program input into and out of the jq implementation.

The initial implementation relies on the jq binary being installed on the host to bootstrap that functionality.

Plans include re-implementing jq in Go to avoid this dependency.

UI

The UI is currently managed by termbox-go. Termbox takes control over the current terminal for the lifespan of the command, draws the state of the application in Cells arranged in rows and columns. Use SetCell to write a character to a cell.

Please read the package documentation in ui/ui.go to learn about data flow and management.

Documentation

The Go Gopher

There is no documentation for this package.

Directories

Path Synopsis
Package json manages applying a program of selectors, processors, and extractors as defined by the jq program against input JSON and producing the result.
Package json manages applying a program of selectors, processors, and extractors as defined by the jq program against input JSON and producing the result.
Package ui handles user input, JSON processing output, and sending interactions and commands to the JSON processor.
Package ui handles user input, JSON processing output, and sending interactions and commands to the JSON processor.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL