jq icon indicating copy to clipboard operation
jq copied to clipboard

Feature request: add support for standard query languages (JSONPath, JSON pointers)

Open eadmaster opened this issue 7 years ago • 7 comments

I'd like to suggest adding support for some standard query languages like JSONPath and JSON pointers (RFC 6901) via cmdline switches. e.g.: jq --jsonpath "/store/book[1]/title" books.json

eadmaster avatar Jul 17 '18 09:07 eadmaster

The syntax should rather be

jq 'jsonpath("/store/book[1]/title")' books.json

With jsonpath/1 being a function that translates path expressions to jq filters.

nichtich avatar May 05 '19 18:05 nichtich

Here you go with JSON Pointer:

jq 'include "jsonpointer"; pointer("/store/book/1/title")' books.json

nichtich avatar May 07 '19 09:05 nichtich

can this be merged with jq so no include "jsonpointer"; is necessary?

eadmaster avatar May 10 '19 17:05 eadmaster

This is the jsonpath statement I'd like to see supported:

The json is an array of items, each one having an id. I'd like to use jsonpath to find the item with id=X. e.g. jq '.[?(@.id = X)]'

seansund avatar Mar 31 '20 15:03 seansund

@seansund wrote:

The json is an array of items, each one having an id. I'd like to use jsonpath to find the item with id=X

For those who don't know, jq already handles this type of query, and in fact makes it easy to distinguish between its two main variants:

  • all such items:

    .[] | select(.id==X)

  • first such item:

    first(.[] | select(.id==X))

pkoppstein avatar Mar 31 '20 15:03 pkoppstein

For the record, JSONPath was standardized on February 2024 as RFC9535 - JSONPath: Query Expressions for JSON.

mmoya avatar Mar 12 '24 10:03 mmoya

Does anyone know if there is any JSONPath implementation written in jq?

wader avatar Mar 12 '24 10:03 wader