jid

package module
v0.7.6 Latest Latest
Warning

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

Go to latest
Published: Mar 31, 2019 License: MIT Imports: 12 Imported by: 11

README

jid

Circle CI

Json Incremental Digger

It's a very simple tool.
You can drill down JSON interactively by using filtering queries like jq.

Suggestion and Auto completion of this tool will provide you a very comfortable JSON drill down.

Demo

demo-jid-main

Installation

With homebrew (for Mac)
brew install jid
With pkg (for FreeBSD)
pkg install jid
Other package management system

Jid can install by package management systems of below OS.

Packaging status

Simply use "jid" command

If you simply want to use jid command, please download binary from below.

https://github.com/simeji/jid/releases

Build

go get -u github.com/simeji/jid/cmd/jid

Usage

Quick start
simple json example

Please execute the below command.

echo '{"aa":"2AA2","bb":{"aaa":[123,"cccc",[1,2]],"c":321}}'| jid

then, jid will be running.

You can dig JSON data incrementally.

When you enter .bb.aaa[2], you will see the following.

[Filter]> .bb.aaa[2]
[
  1,
  2
]

Then, you press Enter key and output [1,2] and exit.

simple json example2

This json is used by demo section.

echo '{"info":{"date":"2016-10-23","version":1.0},"users":[{"name":"simeji","uri":"https://github.com/simeji","id":1},{"name":"simeji2","uri":"https://example.com/simeji","id":2},{"name":"simeji3","uri":"https://example.com/simeji3","id":3}],"userCount":3}}'|jid
With a initial query

First argument of jid is initial query. (Use JSON same as Demo)

demo-jid-with-query

with curl

Sample for using RDAP data.

curl -s http://rdg.afilias.info/rdap/domain/example.info | jid
Load JSON from a file
jid < file.json

Keymaps

key description
TAB / CTRL + I Show available items and choice them
CTRL + W Delete from the cursor to the start of the word
CTRL + U Delete whole query
CTRL + F / Right Arrow (➡) Move cursor a character to the right
CTRL + B / Left Arrow (⬅) Move cursor a character to the left
CTRL + A To the first character of the 'Filter'
CTRL + E To the end of the 'Filter'
CTRL + J Scroll json buffer 1 line downwards
CTRL + K Scroll json buffer 1 line upwards
CTRL + G Scroll json buffer to bottom
CTRL + T Scroll json buffer to top
CTRL + N Scroll json buffer 'Page Down'
CTRL + P Scroll json buffer 'Page Up'
CTRL + L Change view mode whole json or keys (only object)
ESC Hide a candidate box
Option
option description
First argument ($1) Initial query
-h print a help
-help print a help
-version print the version and exit
-q Output query mode (for jq)
-M monochrome output mode

Documentation

Index

Constants

View Source
const (
	DefaultY     int    = 1
	FilterPrompt string = "[Filter]> "
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Engine

type Engine struct {
	// contains filtered or unexported fields
}

func (*Engine) GetQuery

func (e *Engine) GetQuery() QueryInterface

func (*Engine) Run

func (e *Engine) Run() EngineResultInterface

type EngineAttribute

type EngineAttribute struct {
	DefaultQuery string
	Monochrome   bool
	PrettyResult bool
}

type EngineInterface

type EngineInterface interface {
	Run() EngineResultInterface
	GetQuery() QueryInterface
}

func NewEngine

func NewEngine(s io.Reader, ea *EngineAttribute) (EngineInterface, error)

type EngineResult

type EngineResult struct {
	// contains filtered or unexported fields
}

func (*EngineResult) GetContent

func (er *EngineResult) GetContent() string

func (*EngineResult) GetError

func (er *EngineResult) GetError() error

func (*EngineResult) GetQueryString

func (er *EngineResult) GetQueryString() string

type EngineResultInterface

type EngineResultInterface interface {
	GetQueryString() string
	GetContent() string
	GetError() error
}

type JsonManager

type JsonManager struct {
	// contains filtered or unexported fields
}

func NewJsonManager

func NewJsonManager(reader io.Reader) (*JsonManager, error)

func (*JsonManager) Get

func (jm *JsonManager) Get(q QueryInterface, confirm bool) (string, []string, []string, error)

func (*JsonManager) GetCandidateKeys

func (jm *JsonManager) GetCandidateKeys(q QueryInterface) []string

func (*JsonManager) GetFilteredData

func (jm *JsonManager) GetFilteredData(q QueryInterface, confirm bool) (*simplejson.Json, []string, []string, error)

func (*JsonManager) GetPretty

func (jm *JsonManager) GetPretty(q QueryInterface, confirm bool) (string, []string, []string, error)

type Query

type Query struct {
	// contains filtered or unexported fields
}

func NewQuery

func NewQuery(query []rune) *Query

func NewQueryWithString

func NewQueryWithString(query string) *Query

func (*Query) Add

func (q *Query) Add(query []rune) []rune

func (*Query) Clear

func (q *Query) Clear() []rune

func (*Query) Delete

func (q *Query) Delete(i int) []rune

func (*Query) Get

func (q *Query) Get() []rune

func (*Query) GetChar

func (q *Query) GetChar(idx int) rune

func (*Query) GetKeywords

func (q *Query) GetKeywords() [][]rune

func (*Query) GetLastKeyword

func (q *Query) GetLastKeyword() []rune

func (*Query) IndexOffset

func (q *Query) IndexOffset(i int) int

func (*Query) Insert

func (q *Query) Insert(query []rune, idx int) []rune

func (*Query) Length

func (q *Query) Length() int

func (*Query) PopKeyword

func (q *Query) PopKeyword() ([]rune, []rune)

func (*Query) Set

func (q *Query) Set(query []rune) []rune

func (*Query) StringAdd

func (q *Query) StringAdd(query string) string

func (*Query) StringGet

func (q *Query) StringGet() string

func (*Query) StringGetKeywords

func (q *Query) StringGetKeywords() []string

func (*Query) StringGetLastKeyword

func (q *Query) StringGetLastKeyword() string

func (*Query) StringInsert

func (q *Query) StringInsert(query string, idx int) string

func (*Query) StringPopKeyword

func (q *Query) StringPopKeyword() (string, []rune)

func (*Query) StringSet

func (q *Query) StringSet(query string) string

type QueryInterface

type QueryInterface interface {
	Get() []rune
	Set(query []rune) []rune
	Insert(query []rune, idx int) []rune
	Add(query []rune) []rune
	Delete(i int) []rune
	Clear() []rune
	Length() int
	IndexOffset(int) int
	GetChar(int) rune
	GetKeywords() [][]rune
	GetLastKeyword() []rune
	PopKeyword() ([]rune, []rune)
	StringGet() string
	StringSet(query string) string
	StringInsert(query string, idx int) string
	StringAdd(query string) string
	StringGetKeywords() []string
	StringGetLastKeyword() string
	StringPopKeyword() (string, []rune)
}

type Suggestion

type Suggestion struct {
}

func NewSuggestion

func NewSuggestion() *Suggestion

func (*Suggestion) Get

func (s *Suggestion) Get(json *simplejson.Json, keyword string) []string

func (*Suggestion) GetCandidateKeys

func (s *Suggestion) GetCandidateKeys(json *simplejson.Json, keyword string) []string

func (*Suggestion) GetCurrentType

func (s *Suggestion) GetCurrentType(json *simplejson.Json) SuggestionDataType

type SuggestionDataType

type SuggestionDataType int
const (
	UNKNOWN SuggestionDataType = iota
	ARRAY
	MAP
	NUMBER
	STRING
	BOOL
)

type SuggestionInterface

type SuggestionInterface interface {
	Get(json *simplejson.Json, keyword string) []string
	GetCandidateKeys(json *simplejson.Json, keyword string) []string
}

type Terminal

type Terminal struct {
	// contains filtered or unexported fields
}

func NewTerminal

func NewTerminal(prompt string, defaultY int, monochrome bool) *Terminal

func (*Terminal) Draw

func (t *Terminal) Draw(attr *TerminalDrawAttributes) error

type TerminalDrawAttributes

type TerminalDrawAttributes struct {
	Query           string
	Contents        []string
	CandidateIndex  int
	ContentsOffsetY int
	Complete        string
	Candidates      []string
	CursorOffset    int
}

Directories

Path Synopsis
cmd
jid

Jump to

Keyboard shortcuts

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