How can we query whether the item is in the output or not with linq?

How can we query whether the item is in the output or not with linq?

For a True / False Return:
JSonResp…Select(Function (x) x.Item(…).Contains(12345)

1 Like

Hi @Bedirhan_Ozkan

- Assign -> Bool_Flag = If(JsonResponse.Any(Function(X) X.Item("gacerlilikTarihi").Contains("20240101")),True,False)

Bool_Flag is the Boolean datatype variable.
If output is True then the Input contains in the Json
If output is false then the Input doesn’t contains in the Json

Hope it helps!!

1 Like

Maybe you can also elaborate more on item is in the input
When it is meant, if the JSON Key/Property is present, then we would check JSonRespionse Properties Set

1 Like

@Bedirhan_Ozkan

isItemPresent = JObject.Parse(jsonString).Properties().Any(Function(p) p.Value.ToString() = "your_item_value")

1 Like

Hi @Bedirhan_Ozkan

Check this:

Bool_Result = JsonResponse.Any(Function(a) a("gacerlilikTarihi")?.ToString().Contains(Item))

1 Like

Hi @Bedirhan_Ozkan

jsonResponse.Select(Function(x) x.Item("gecerlilik Tarihi").ToString).Any(Function(y)y.Contains("20240101"))

1 Like

I want to make the date value (20240101) i.e. “item” dynamic

Okay @Bedirhan_Ozkan

Then store the value in a variable called Item.

- Assign -> item = "20240101"

- Assign -> Bool_Flag = If(JsonResponse.Any(Function(X) X.Item("gacerlilikTarihi").Contains(item)),True,False)

Hope you understand!!

1 Like

Hi @Bedirhan_Ozkan

As your variable is already storing in a item variable.
You can use item in the place of the value

1 Like

thank you, i found the solution

1 Like

@Bedirhan_Ozkan
kindly note the 2 different Contains

String Method Contains:

And LINQ Operator Contains:

  • The LINQ operator Contains checks whether an element is contained in the set of elements
  • The String method checks whether a string occurs in another string.

Thus, an implementation within the part:

would also return True when 20240101 is checked within 5202401010

So we suggest cross-checking with the above-given description if the selected solution will have risk of side-effect when processing the data

1 Like

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