JSONpath query that returns paths to the matches - Mailing list pgsql-novice

From Alex R
Subject JSONpath query that returns paths to the matches
Date
Msg-id CANK1NR1E1CyHcqF+xQvBYBY0+G4GGL_HKDDSad2am74zz_N3mg@mail.gmail.com
Whole thread Raw
Responses Re: JSONpath query that returns paths to the matches
List pgsql-novice
Hi,

I am trying to figure out whether Postgres 14 allows me to find the paths to certain values in the JSON, rather than the values themselves. To illustrate, here is a test query:

SELECT JSONB_PATH_QUERY($${
  "this": "that",
  "that": [{"x": "aaa"},{"y": "missed"}],
  "nested": {
        "deep": {
        "x": "bbb"
      }
  }
}$$, 'strict $.**."x"');

It returns 2 matches: "aaa" and "bbb". However, what I'd like to get instead is 2 paths that point to the matches, i.e.,:
- $.that[0]
- $.nested.deep

Can this be accomplished using means that are available out of the box? If not, what would be a sane way of implementing it?


Thank you for your help,
Alex

pgsql-novice by date:

Previous
From: Greg Rychlewski
Date:
Subject: Streaming Replication Protocol and Logical Replication
Next
From: "David G. Johnston"
Date:
Subject: Re: JSONpath query that returns paths to the matches