Skip to content

jkit get

Walk a JSON document with a dotted path and print the value at the end of it.

bash
jkit get <path>   # full name
jkit g <path>     # short alias

Synopsis

jkit get <path>
jkit g   <path>
ArgumentDescription
<path>A .-separated path. Use string keys for objects and integer indices for arrays.

Reads from stdin or the clipboard — see Input handling.

What it does

  • Walks the path one segment at a time.
  • For objects: looks up the segment as a key.
  • For arrays: parses the segment as an integer index.
  • For string leaves: prints the raw string (no surrounding quotes), so you can pipe it directly into other tools.
  • For everything else (numbers, booleans, null, objects, arrays): prints a properly formatted JSON literal.

Examples

Walk into nested objects

bash
> echo '{"user":{"name":"alice","age":30}}' | jkit g user.name
alice

> echo '{"user":{"name":"alice","age":30}}' | jkit g user.age
30

Index into arrays

bash
> echo '{"items":[{"id":1},{"id":2},{"id":3}]}' | jkit g items.1.id
2

Returning a subtree

When the value isn't a scalar, jkit g formats it with 4-space indent:

bash
> echo '{"items":[{"id":1,"name":"x"},{"id":2,"name":"y"}]}' | jkit g items.0

{
    "id": 1,
    "name": "x"
}

Combining with shell tools

Because string leaves print raw, jkit g composes with xargs, read, awk, etc.:

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

Errors

Errors include the path where things went wrong, so you can debug quickly:

bash
> echo '{"a":1}' | jkit g missing
jkit: key "missing" not found at missing

> echo '{"items":[1,2,3]}' | jkit g items.99
jkit: index 99 out of range [0, 3) at items.99

> echo '{"items":[1,2,3]}' | jkit g items.abc
jkit: array index must be integer at items.abc, got "abc"

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