Extract a value from JSON

I need to get the “CreatedAt” from json based on the ConversationID .

I tried this DeserializeJsonOutputGetConversationID(“data”).Where(Function (x) x (“attributes”)(“createdAt”).value(of string).Equals(ConversationID)).Select(Function (x) x (“createdAt”).value(of string)).toArray but this is not working
JsonBody.txt (6.4 KB)

please share with us the JSON sample as Text file

is CreatedAt ~ ConversationID?

@tharani.natarajan

DeserializeJsonOutputGetConversationID(“data”).Where(x => x[“attributes”][“createdAt”].Value(Of String) == ConversationID).Select(x => x[“attributes”][“createdAt”].Value(Of String)).ToArray()

Use this hope it works

Edited the post. No createdAt will be time( “createdAt”: “2023-07-13T06:54:38.919Z”), whereas conversationId will like this (Bold is conversation Id )

“resource”: {
“data”: {
“type”: “conversation”,
“id”: “64af9fad4a95dc47abd21ede”
}
},

so when the filter shoud be done on the id then we would recommend:

DeserializeJsonOutputGetConversationID("data").Where(Function (x) x("id").value(of string).Equals(ConversationID)).Select(Function (x) x ("attributes")(“createdAt”).value(of string)).toArray

We interpreted your input as:

  • get the createdAt value for an item with a particular conversationID

Using the Query Syntax allows also to increase the readability of the LINQ statement

Thanks a lot! I had to match with conversation Id not with workItem Id .I have replaced it accordingly based on you answer
DeserializeJsonOutputGetConversationID(“data”).Where(Function (x) x (“relationships”)(“resource”)(“data”)(“id”).value(Of String).Equals(ConversationID)).Select(Function (x) x (“attributes”)(“createdAt”).value(Of String)).toArray

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