Skip to content

wuhan005/jkit

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

16 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

🔧 jkit

Go Go Reference License

A small, fast JSON CLI for the things you actually do every day: pretty-print, fold deeply nested trees, pluck out a single value, or build a JSON array from a list of lines. Reads from stdin or the system clipboard — copy a JSON blob, run jkit f, done.

Features

Command Alias What it does
jkit format f Pretty-print JSON (4-space indent, keeps numeric precision)
jkit cut <depth> c Collapse nodes deeper than <depth> into compact summaries
jkit get <path> g Extract a sub-value by dotted path, e.g. data.items.0.id
jkit maker m Turn line-separated text into a JSON string array

Install

go install github.com/wuhan005/jkit/cmd/jkit@latest

From source:

git clone https://github.com/wuhan005/jkit.git
cd jkit
go install ./cmd/jkit

Requires Go 1.21+. The binary is a single static file with no runtime dependencies.

Input handling

jkit figures out where to read JSON from automatically:

  • Pipe / redirectecho '{"a":1}' | jkit f or jkit f < data.json
  • Clipboard — when stdin is a terminal, falls back to the system clipboard. Copy a JSON blob anywhere, then just run jkit f.

If stdin has no data and the clipboard is empty, jkit exits with no input from stdin or clipboard.

Commands

jkit f — Format JSON

Pretty-print with 4-space indent. Numbers are decoded with json.Number, so big integers like 9223372036854775807 survive round-trip without becoming 9.2233720368e+18.

> echo '{"data":{"area":"东京Amazon数据中心","country":"日本","ip":"52.68.96.58"},"error":0,"msg":"success"}' | jkit f

{
    "data": {
        "area": "东京Amazon数据中心",
        "country": "日本",
        "ip": "52.68.96.58"
    },
    "error": 0,
    "msg": "success"
}

jkit c <depth> — Fold JSON

Collapse anything deeper than <depth> levels into { N items dict } / [ N items array ] summaries. Object keys are emitted in lexicographic order, so the same input always produces the same output (handy for diffs).

Omit <depth> to keep the full tree.

> jkit c 2

{
    "code": 0,
    "message": "success",
    "result": {
        "main_section": { 4 items dict },
        "section": [ 1 items array ]
    }
}

jkit g <path> — Extract by path

Walk a .-separated path. Use integer indices for array elements. String leaves print without quotes (so you can pipe them straight into other tools); other leaves print as JSON literals.

> jkit g result.main_section.episodes.0

{
    "badge": "会员",
    "id": 341208,
    "title": "1"
}

> jkit g result.main_section.episodes.0.title
1

> curl -s https://api.example.com/user | jkit g name | xargs -I{} echo "Hello {}"

Errors include the path where things broke:

> echo '{"a":1}' | jkit g a.b
jkit: cannot descend into json.Number at a.b

jkit m — Build a JSON string array

Read line-separated text, emit a JSON array. Empty lines are dropped, each line is trimmed, and \r\n is handled. Pass -u (or --unique) to drop duplicates.

> cat | jkit m
Hi, I'm E99p1ant. 🍆
🐭 Focus on Golang.
🏠 Blog at github.red.

[
    "Hi, I'm E99p1ant. 🍆",
    "🐭 Focus on Golang.",
    "🏠 Blog at github.red."
]
> printf 'apple\nbanana\napple\n' | jkit m -u

[
    "apple",
    "banana"
]

License

MIT © wuhan005

About

🔧 Your clipboard's JSON Swiss Army knife.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages