How to Handle Missing JSON Data and Retrieve Alternative Values

Hi,

I’m working with JSON data, and I need to handle a situation where I fetch a value from the JSON, but if that specific data isn’t available, I need to retrieve another value. Here’s an example:

I have this line of code:
ModifiedDate = DeserializeJsonOutputGetConversationID(“data”)(“attributes”)(“modificationHistory”)(“assignedTeamsAt”).ToString

If “assignedTeamsAt” is not available, I want to do this:
ModifiedDate = DeserializeJsonOutputGetConversationID(“data”)(“attributes”)(“ModifiedDate”).ToString

I tried using containsKey but getting the below error

Hi @tharani.natarajan ,

Could you maybe check the below post on a similar issue :

I believe you have missed out the Casting.

1 Like

Try with this expression in assign activity

Stroutput = If(DeserializeJsonOutputGetConversationID(“data”)(“attributes”).ContainsKey(“modificationHistory”) AndAlso DeserializeJsonOutputGetConversationID(“data”)(“attributes”)(“modificationHistory”).ToObject(Of JObject)().ContainsKey(“assignedTeamsAt”), DeserializeJsonOutputGetConversationID(“data”)(“attributes”)(“modificationHistory”)(“assignedTeamsAt”).ToString, DeserializeJsonOutputGetConversationID(“data”)(“attributes”)(“ModifiedDate”).ToString)

Hope this helps

Cheers @tharani.natarajan

It would be helpful

when we can refer to the JSON. Feel free to share it with us as a Text file

Lets assume attributes / modification history will be a JObject. We could do e.g.:

DeserializeJsonOutputGetConversationID(“data”)(“attributes”).Value(Of JObject).ContainsKey(“ModifiedDate”)

There are also other techniques e.g. working with selecttoken

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