Find json object in json array

I am having a hard time finding an asnwer.

If I have the following json array

[{"product_id":"123","product_name":"Beans"},
{"product_id":"456","product_name":"Corn"},
{"product_id":"789","product_name":"Cats"}]

And I want to search for product_id 456 and get the entire json object how would I do that? I am trying to avoid a for each.

@LeftBrainCo
Find starter help here:
FindObjectInArray.xaml (6.2 KB)
using
demo1.json (135 Bytes)

implementing:
JsonArray.Cast(Of JObject).Where(Function (x) x("product_id").toString.Equals("456")).toList
and returning a list of JObjects with the found JObjects

1 Like

That works quite nice thank you! While researching I also found you can do it like this.

jsonArray_TheArray.SelectToken(“$.[?(@.product_id==456)].product_name”)
jsonArray_TheArray.SelectToken(“$.[?(@.name==‘bob’)].product_name”)

You can test the Json path’s with this handy site if whoever finds this need a resource.

This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.