2 releases
new 0.1.2 | Jan 15, 2025 |
---|---|
0.1.0 | Jan 13, 2025 |
#1059 in Command line utilities
37 downloads per month
8KB
52 lines
jpq
A JSONPath command line tool to extract values from a JSON value.
Usage
jpq <xpath> <filename>
The xpath
argument is a RFC
9535 JSONPath expression. The
extracted result is printed on standard output.
Overview of JSONPath Syntax
This is copied from RFC 9535 JSONPath: Query Expressions for JSON
Syntax Element Description
$ root node identifier (Section 2.2)
@ current node identifier (Section 2.3.5) (valid only within filter selectors)
[<selectors>] child segment (Section 2.5.1): selects zero or more children of a node
.name shorthand for ['name']
.* shorthand for [*]
..[<selectors>] descendant segment (Section 2.5.2): selects zero or more descendants of a node
..name shorthand for ..['name']
..* shorthand for ..[*]
'name' name selector (Section 2.3.1): selects a named child of an object
* wildcard selector (Section 2.3.2): selects all children of a node
3 index selector (Section 2.3.3): selects an indexed child of an array (from 0)
0:100:5 array slice selector (Section 2.3.4): start:end:step for arrays
?<logical-expr> filter selector (Section 2.3.5): selects particular children using a logical expression
length(@.foo) function extension (Section 2.4): invokes a function in a filter expression
Example
$ jq '$.store.book[*].author' test-data/rfc9535-fig1.json
[
"Nigel Rees",
"Evelyn Waugh",
"Herman Melville",
"J. R. R. Tolkien"
]
Dependencies
~6–13MB
~157K SLoC