question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

JSONPath array filter can't refer to root object ($)

See original GitHub issue

The following JSONPath expression: $.included[?(@.id == $.data.relationships.target.id)] would be expected work with the following JSON, but does not: http://api.mocki.io/v1/9c54d246

Individually, $.included[?(@.id == "foo")] and $.data.relationships.target.id work, but not when combined.

Desktop (please complete the following information):

  • OS: Big Sur
  • Installation Method: download
  • App Version: v2021.1.0

Issue Analytics

  • State:open
  • Created 3 years ago
  • Comments:8 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
lguzik-bkpcommented, Mar 30, 2021

It will be a breaking change. The jq syntax is more complex, but more powerful at the same time. The OP’s case would look like this if used in CLI:

jq '. as $parent | .included[] | select(.id == $parent.data.relationships.target.id)' input.json
{
  "id": "foo",
  "attributes": {
    "name": "i_am_foo"
  }
}
1reaction
akshaymattoocommented, Mar 24, 2021

@pvarga-dni It seems the issue is with the npm module that is being used in the project. Insomnia uses jsonpath to handle these queries which are not able to process these requests. I have raised an issue with them and we can see if they can support this, details of the issue can be found here. If they get us a fix then all we need to do is update the npm module and it will be working. If you refer to this link, you will see your query works here fine. Another solution to this problem can be we look into the implementation of this type of query in projects p1 and p2 which are java and scala based projects. Once we understand we make the contribution to jsonpath module and get this working. @develohpanda @dimitropoulos Can you please verify the above details.

Read more comments on GitHub >

github_iconTop Results From Across the Web

JSONPath: Get root array object using filter of child value
I need to get whole sport object where "inplay == 0" using JsonPath expression. Result should look like that: { "name": "Tennis", "regions":...
Read more >
How to Use JSONPath to filter JSON data - Telerik Reporting
In this article we are going to discuss how to use JSONPath expressions in the Data Selector in order to query and filter...
Read more >
JSON Path explained - Elements Connect for Jira Server/Data ...
The root element in JSONPath is always referred to as $ regardless if it is an object or array.
Read more >
Using JSONPath effectively in AWS Step Functions
This post uses a sample application to highlight effective use of JSONPath and data filtering strategies that can be used in Step Functions....
Read more >
12: 9.15. JSON Functions and Operators - PostgreSQL
The field/element/path extraction operators that accept integer JSON array subscripts all support negative subscripting from the end of arrays. The standard ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found