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

Created on 17 Jul 2018  路  5Comments  路  Source: stedolan/jq

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

jq function library

Most helpful comment

Here you go with JSON Pointer:

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

All 5 comments

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.

Here you go with JSON Pointer:

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

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

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

Was this page helpful?
0 / 5 - 0 ratings

Related issues

kaihendry picture kaihendry  路  4Comments

rclod picture rclod  路  4Comments

tischwa picture tischwa  路  4Comments

rubensayshi picture rubensayshi  路  3Comments

benjamin-bin-shen picture benjamin-bin-shen  路  3Comments