0

I have the following JSON

{
    “Record”: [
  {
    “FirstName": “John”,
    “LastName”: “Smith”,
    “City”: “Chicago”,
    “Possessions”: [
      {
        “Item”: “TV”
      },
      {
        “Item”: “XBOX-S”
      },
      {
        “Item”: “DVR”
      },
      {
        “Item”: “Setup Box”
      }
    ]
  },
  {
    “FirstName": “Jane”,
    “LastName”: “Doe”,
    “City”: “Seattle”,
    “Possessions”: [
      {
        “Item”: “DVR”
      },
      {
        “Item”: “PS5”
      },
      {
        “Item”: “FireStick”
      }
    ]
  },
  {
    “FirstName": “Jane”,
    “LastName”: “Lee”,
    “City”: “Dallas”,
    “Possessions”: [
      {
        “Item”: “TV”
      },
      {
        “Item”: “PS5”
      },
      {
        “Item”: “FireStick”
      }
    ]
  }
 ]
}

How do I get a table of First Name and Last Name by matching a particular possession ("TV") using JMESPATH query? I need to match the Value in the Array Possessions for each entry in the Record

I have tried using the following query, but it does not work,

Record[?contains(Possessions[].Item, `TV`) == `true`]

anyone knows how this request will work or point me in the right direction, it would be greatly appreciated.

  • What you are trying should work; although it should be simplified to ```Record[?contains(Possessions[].Item, `TV`)]```. This said, your JSON is invalid, and that's maybe what is causing your issue. Your quotes are literal quotation marks, `“”`, ASCII 147 and 148 and not a double quote, `"`, ASCII 34. (https://www.ascii-code.com) – β.εηοιτ.βε Aug 24 '22 at 18:53
  • 1
    Thanks That worked, would you also know the query if I want to display the other values where this condition does not meet, like list of Records where the Possessions does not have the TV. – Arshdeep Aug 25 '22 at 05:49
  • 1
    got it working ```Record[?!contains(Possessions[].Item, `TV`)]``` this returns the other values where Possessions list do not have TV – Arshdeep Aug 25 '22 at 06:03

0 Answers0