JSONata - am I missing something?

I have a simple JSON

  "customers": [
      "id": "XYZ-ABC-DEF",
      "data": {
        "locations": [
            "location_id": 1,
            "location_name": "Main",
            "location_attr": "blue"
            "location_id": 2,
            "location_name": "Secondary"

I do a simple op:

customers[][data.locations.location_attr = "blue"]

And it works, returns the entire 'customer' object. But only as long as only one record has the "location_attr" field. As soon as I add "location_attr" to a second record - it stops working.

But a different op is still possible:

customers.data.locations[location_attr = "blue"]

However, this defeats the purpose - I need the customer id.

It's driving me nuts :slight_smile: Please point me to the explanation/solution!

What about this:

customers.data.locations[location_attr = "blue"].$$

And possibly:

customers.data.locations[location_attr = "blue"].$$.customers.id

To only get the id.

Please, don't ask for an explanation... but $$ and $ are "magical" (at least for me) in Jsonata.

Thanks! Your suggestion looked promising, but matches the whole structure :frowning: I need only the customer with the attribute.

So it looks like a limitation :frowning:

I had to get rid of embedded structures and add redundancy to the data.