LeftBrainCo
(Louis McKernan)
September 24, 2020, 5:06pm
1
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.
ppr
(Peter Preuss)
September 24, 2020, 8:03pm
2
@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
LeftBrainCo
(Louis McKernan)
September 24, 2020, 8:44pm
3
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.
system
(system)
Closed
September 27, 2020, 8:45pm
4
This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.