FarFarAway
FarFarAway

Reputation: 1115

Perform complex jsonpath query

I have the following json response. I want to filter using json path as follows: Get the first date for person ec7e231e-1fed-4860-a1ab-c2e3248a183e where 1. the date is not null and 2. the exam array is empty and 3. the absent flag is false

[
  {
    "Person": {
      "ReferenceKey": "ec7e231e-1fed-4860-a1ab-c2e3248a183e",
      "fname": "john",
      "lname": "anderson",
      "adress": null
    },
    "days": [
      {
        "date": null,
        "absent": false,
        "holiday": false,
        "exam": [],
        "blockingtimes": []
      },
      {
        "date": "2021-02-19",
        "absent": false,
        "holiday": false,
        "exam": [],
        "blockingtimes": []
      },
      {
        "date": "2021-02-20",
        "absent": false,
        "holiday": false,
        "exam": [],
        "blockingtimes": []
      }
    ]
  },
  {
    "Person": {
      "ReferenceKey": "ec7e231e-1fed-4860-a1ab-c2e3248a1900",
      "fname": "manny",
      "lname": "panny",
      "adress": null
    },
    "days": [
      {
        "date": null,
        "absent": false,
        "holiday": false,
        "exam": [],
        "blockingtimes": []
      },
      {
        "date": "2021-02-19",
        "absent": false,
        "holiday": false,
        "exam": [],
        "blockingtimes": []
      },
      {
        "date": "2021-02-20",
        "absent": true,
        "holiday": false,
        "exam": [],
        "blockingtimes": []
      }
    ]
  }
]

so far i was only able to retrieve all person uuids $..person.mitarbeiterReferenceKey

Upvotes: 0

Views: 232

Answers (1)

Dmitri T
Dmitri T

Reputation: 167992

Something like

$.[?(@.Person.ReferenceKey == 'ec7e231e-1fed-4860-a1ab-c2e3248a183e')].days[?(@.date != null && @.absent == false && @.exam.length() == 0)])

enter image description here

More information:

Upvotes: 1

Related Questions