SelectTokens with not exists

272 Views Asked by At

I'm trying to find if there's a nice way using SelectTokens and JsonPath to find all controls with type="check" and no "options". So an example JSON could be:

Value = @"{
    ""subsections"": [
        {
        ""name"": ""Subsection Name"",
        ""caption"": ""Subsection Caption""
        },
    ],
    ""controls"": [
       { ""type"" : ""check"", 
           ""name"" : ""Checkbox2"",
           ""caption"" : ""Checkbox Caption 2"",
           ""options"" : [
               { ""caption"" : ""Yes"" },
               { ""caption"" : ""No"" }
           ]
       },
       { ""type"" : ""check"", 
           ""name"" : ""Checkbox2"",
           ""caption"" : ""Checkbox Caption 2"",
       }
    ]
}"

I'm trying things like: $..controls[?(@.type=='check' && !(@.options))] but I can't see any option to test for a not exists.

The only option that I can think of is getting all check types and then using Linq to filter those without options. Just wondering if there is a way to do it solely through JsonPath?

Kind regards Sidharth

0

There are 0 best solutions below