Comparison for attributes using contains in Map format

Hi All,
I need to implement contains for the attributes transformed as Map

I have transformed a json into Map. I am able to use it inside json file as #{payload.status} for which I get the value and also works on switch case
doSwitch(“#{payload.status}”)

But I am unable to implement for the below:
eg: 1
doIf(session => session(“payload.status”).as[String].contains(“ABC”)) { }

eg: 2
doIf(session => session(“#{payload.status}”).as[String].contains(“ABC”)) { }

–A

Are you sure that payload.status contains your map? Perhaps its payload. The doSwitch has the expression payload.status and that means get me the value of status key from the Map payload stored in the session. Perhaps you want to do a contains on a different value thats addressed by a different key :slight_smile:

1 Like

Maybe try something like this

doIf(session => session("payload").as[Map[String,Any]]("status").toString.contains("ABC"))

Hi @shoaib42 … my bad… actually the value fetched is in the below format:

So how do I implement for two layer Map.

What you are asking is simply another step, try the following.

doIf(session => session("payload").as[Map[String,Map[String,Any]]]("status")("update").toString.contains("ABC"))

Hi @shoaib42

I am getting an error on the key value

it doesnt throw error for the below but the condition is always false.

-A

You are missing session => and I think my solution might not work and you might have to use a very verbose way of doIf like. It would be easier for you to extract this value from the JSON response using JmesPath or JsonPath and transform and store in the session

doIf( session => {
val payload = session("payload").as[Map[String,Any]]
val status = payload("status").asInstanceOf[Map[String,Any]]
status("update").toString.contains("ABC"))
})

PS - I’m typing this on my cellphone so pardon the syntactical errors

Thanks @shoaib42 it worked by using get(“key”) which fetched value of the Key.

doIfOrElse(session => session(“payload”).as[Map[String, Any]].get(“status”).toString.contains(“ASS”))

-A