| Crates.io | jpq |
| lib.rs | jpq |
| version | 0.1.4 |
| created_at | 2025-01-13 17:14:34.980308+00 |
| updated_at | 2025-02-15 12:35:28.569457+00 |
| description | A JSONPath command line tool to extract values from a JSON value. |
| homepage | |
| repository | https://codeberg.org/KMK/jpq |
| max_upload_size | |
| id | 1514906 |
| size | 46,052 |
A JSONPath command line tool to extract values from a JSON value.
jpq [--arg <name> <value>] [--argjson <name> <value>]
[--color <auto | always | never | unless-compact>] [--compact-output]
<JSONPath expression> [filename]
The JSONPath expression argument is a RFC
9535 JSONPath expression. The
extracted result is printed on standard output.
The authors of all books in the store:
$ jpq '$.store.book[*].author' test-data/rfc9535-fig1.json
[
"Nigel Rees",
"Evelyn Waugh",
"Herman Melville",
"J. R. R. Tolkien"
]
all books cheaper than 10:
$ jpq --argjson max 10 '$..book[?@.price<var("max")]' test-data/rfc9535-fig1.json
[
{
"category": "reference",
"author": "Nigel Rees",
"title": "Sayings of the Century",
"price": 8.95
},
{
"category": "fiction",
"author": "Herman Melville",
"title": "Moby Dick",
"isbn": "0-553-21311-3",
"price": 8.99
}
]
This is copied from RFC 9535 JSONPath: Query Expressions for JSON
$: root node identifier@: current node identifier (valid only within filter selectors)[<selectors>]: child segment: selects zero or more children of a node.name: shorthand for ['name'].*: shorthand for [*]..[<selectors>]: descendant segment: selects zero or more descendants of a node..name: shorthand for ..['name']..*: shorthand for ..[*]'name': name selector: selects a named child of an object*: wildcard selector: selects all children of a node3: index selector: selects an indexed child of an array (from 0)0:100:5: array slice selector: start:end:step for arrays?<logical-expr>: filter selector: selects particular children using a logical expressionlength(@.foo): function extension: invokes a function in a filter expressionYou need a Rust compiler, see https://www.rust-lang.org/tools/install if you do not yet have one. The minimum Rust compiler version supported is 1.80.0.
Then just run
$ cargo install jpq
This installs jpq under ~/.cargo/bin. This should be in your PATH
so just typing jpq will run it; otherwise you'll need to type its
whole path: ~/.cargo/bin/jpq.
match and search.--color <when> argument to force color on or off,--arg <name> <value> and --argjson <name> <value> options,
and var(...) function extension to access it,--compact-output option,