Extract a nested JSON value using a dot-path
npm install --global json-extract-cli$ json-extract --help
Usage
$ json-extract <path> [options]
Options
--file <path> Read from file instead of stdin
--json Pretty-print output as JSON
--fallback <value> Return fallback value if path not found
--quiet Suppress errors, exit 0 on failure
Examples
$ echo '{"user":{"email":"a@b.com"}}' | json-extract "user.email"
a@b.com
$ json-extract "user.name" --file data.json
John
$ json-extract "missing.path" --fallback "default"
default$ echo '{"user":{"name":"John","email":"john@example.com"}}' | json-extract "user.email"
john@example.com$ json-extract "user.name" --file data.json
John$ echo '{"users":[{"name":"Alice"},{"name":"Bob"}]}' | json-extract "users"
[{"name":"Alice"},{"name":"Bob"}]$ echo '{"users":[{"name":"Alice"}]}' | json-extract "users" --json
[
{
"name": "Alice"
}
]$ echo '{"user":{"name":"John"}}' | json-extract "user.age" --fallback "unknown"
unknown$ echo '{"user":{"name":"John"}}' | json-extract "user.age" --quiet
$ echo $?
0The tool accepts JSON input from stdin or a file and extracts values using dot-notation paths.
- Strings
- Numbers
- Booleans
- null
- Arrays (returns full array as JSON)
- Objects (returns full object as JSON)
Use dot-notation to access nested properties:
user.namedata.items.0.idconfig.settings.display.theme
MIT