Home > Software design >  Where clause in JSONata
Where clause in JSONata

Time:06-28

Is there anyway to extract value according to id in an array using JSOnata expression. I wan't to access Status acccroding to specific tag in following array? As an example Status of id_tag equals"B4A63CDF".

[{"Status":"Expired","id":1,"id_tag":"B4A63CDF","name":"New","expiry":"2022-06-25T11:30:00.000Z","group_m":"Premium","In_transaction":false,"blocked":false},{"Status":"Invalid","id":2,"id_tag":"B5A86CXF","name":"New","expiry":"2022-06-22T11:30:00.000Z","group_m":"Premium","In_transaction":false,"blocked":false}]

CodePudding user response:

Yeah, this is an example where JSONata is very comfortable to use, you need to filter your array by the id_tag field and then just get the prop you want from the matching item:

$[id_tag="B4A63CDF"].Status

Feel free to play with my solution here: https://stedi.link/i6ntGoX

  • Related