0

Here is a json snippet containing a definition structure :

{
  "Type": "page",
  "Label": "Test",
  "Children": {
    "crud": {
      "Type": "crud",
      "Datasource": "crud_data",
      "Children": {
        "level1": {},
        "group": {
          "Type": "group",
          "level2": {},
          "Children": {
            "level3a": {},
            "level3b": {},
            "level3c": {}
          }
        }
      }                        
    }
  }
}

I'm trying to find a JSON expression to find every key under "Children", which do not contain any "Type" property inside.

How to say "no Type property" inside an object ?

In the example, I'm expecting this result:

[
  "level1",
  "level3a",
  "level3b",
  "level3c"
]

Note the "crud" and "group" are excluded because they define a "Type" property. Other objects are empty in the example, but could contain properties other the Type and should still match.

I imagine a solution like this : $..Children.*[?(a filter here saying no Type)]~

Thank you for your help

NoDataFound
  • 11,381
  • 33
  • 59
Cristof
  • 26
  • 1

1 Answers1

0

For most implementations, @.Type on its own should be an existence check and can be negated with !. So this should get you most of the way there:

$..[?(!@.Type)]

The problem that this presents is that this returns every child value that doesn't have a Type property, regardless of what kind of value that is. For example, "page" doesn't have a Type property because it's not an object; it doesn't have any properties. But you only want objects.

But JSON Path doesn't have a way to isolate a particular kind of value.

If you were to take the result of this path and then filter for objects, you should get what you want.

gregsdennis
  • 7,218
  • 3
  • 38
  • 71