jqlang / jq

Command-line JSON processor
https://jqlang.github.io/jq/
Other
29.59k stars 1.54k forks source link

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

Open eadmaster opened 5 years ago

eadmaster commented 5 years ago

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

nichtich commented 5 years ago

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 commented 5 years ago

Here you go with JSON Pointer:

jq 'include "jsonpointer"; pointer("/store/book/1/title")' books.json
eadmaster commented 5 years ago

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

seansund commented 4 years ago

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)]'

pkoppstein commented 4 years ago

@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:

mmoya commented 3 months ago

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

wader commented 3 months ago

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