'How to use JSONPath to filter JSON body with nested arrays

This is the JSON Path I have been using:

$..products[?(@.category == 'merchant_cards' && @.countries[0].abbr == 'US' && @.skus[0].min < '25')]

However, I am getting an error end of input expected at 1:12

Here is an excerpt of the body:

[
  {
    "id": "ACGZXBCIGX8Y",
    "name": "Overstock.com",
    "currency_codes": [
      "USD"
    ],
    "skus": [
      {
        "min": 5,
        "max": 500
      }
    ],
    "countries": [
      {
        "abbr": "US"
      }
    ],
    "category": "merchant_cards",
    "disclosure": "",
    "description": "",
    "images": [
      {
        "src": "https://giftrocket-s3.imgix.net/Brands/US/Overstock/Digital/Overstock.png",
        "type": "card"
      }
    ]
  },

I want to be able to filter on some nested lists and that seems to be causing the problems.

For example, I want only those in the US. countries is a list of one, which has a node of abbr which can have multiple values.



Solution 1:[1]

When I complete the json array, this works:

$[?(@.category == 'merchant_cards' && @.countries[0].abbr == 'US' && @.skus[0].min < 25)]

I also changed the min limit to an int.

Try it on https://jsonpath.com/

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1