0

I want to find all entries where any endDate is lower than a certain date.

What I did manage to get to work is this:

[?parentalControlSettings.legalAgeGroupRule=='Allow'].{id: appId, displayName: displayName, secretsCount: length(passwordCredentials), endDates: passwordCredentials[*].endDate}

I want something like passwordCredentials.endDate<='2020-31-15T09:54:51.603361+00:00' However, even something like contains(2019) would be ok.

This is my data:

[
    {
        "appId": "d172bbcb-4f30-49c6-a42e-496b4fdcd0b4",
        "displayName": "myApp",
        "parentalControlSettings": {
            "countriesBlockedForMinors": [],
            "legalAgeGroupRule": "Allow"
        },
        "passwordCredentials": [
            {
                "additionalProperties": null,
                "customKeyIdentifier": null,
                "endDate": "2117-11-15T09:54:51.603361+00:00",
                "keyId": "f327e987-176a-4bc2-b733-4b0bd19e8b83",
                "startDate": "2017-11-15T09:54:51.603361+00:00",
                "value": null
            },
            {
                "additionalProperties": null,
                "customKeyIdentifier": null,
                "endDate": "2019-11-15T09:54:51.603361+00:00",
                "keyId": "f327e987-176a-4bc2-b733-4b0bd19e8b83",
                "startDate": "2017-11-15T09:54:51.603361+00:00",
                "value": null
            }
        ]
    }
]
AmanGarg-MSFT
  • 1,123
  • 6
  • 10
Alex AIT
  • 17,361
  • 3
  • 36
  • 73
  • 1
    You need to modify the string to check the year and you can't do it in JMES Path. So you can do it in jq or you can do in the language which use jmespath. For example if you use javascript with JMESPath lib you can put retrieve all the date(in string) and then convert them into date in js and then filter all element in the array which are under a certain date(still in js) and then in JMESPath check if the object you have in your data is in the array of date(in JMESPath) – bosskay972 Aug 23 '19 at 09:46
  • But I can do at least "string comparison", right? This works: `[?parentalControlSettings.legalAgeGroupRule>'A'].{...}`. So I could build something with that I guess. What I can't figure out is how to match anything within this `passwordCredentialsArray`. – Alex AIT Aug 23 '19 at 09:54
  • Pretty tricky but it doesn't work well, the string comparison exist but doesn't work well in your case, for example: `'2017-11-15T09:54:51.603361+00:00' < '2019-11-15T09:54:51.603361+00:00'` return `true` but this `'217-11-15T09:54:51.603361+00:00' < '2019-11-15T09:54:51.603361+00:00'` return `false` so I don't think it's okay to use this method. So I think you should use jq or you should use the host language of jmespath to main this problem – bosskay972 Aug 23 '19 at 10:03
  • 1
    Yeah, even tough I have trust that I will always get a correct year in my case, it seams that I might be trying to solve a problem with the wrong tool for the job. Thank you for taking the time to comment. – Alex AIT Aug 23 '19 at 10:09
  • You can do string comparison only if you use a comparable date set for example [1000,9999] it's comparable because any all number between 1000 and 9999 possess 4 digit, and could be comparable because there is no number which start by the same 2 digit with a different number of digit. For example 1000 and 1001 start by 10 they are comparable because they have the same number of digit, if we take the same example than before: 217 and 2117 could be comparable because they in fact start with the same 2 digit but doesn't have the same amount of digit, so JMESPath will return true to '217' > '2117' – bosskay972 Aug 23 '19 at 12:04

0 Answers0