I have a JSON string that I need to process and I am mapping it in the following manner:
val jsonMap = mapper.readValue[Map[String, Object]](jsonString)
My jsonMap
contains the following value:
Map(k1 -> List(Map(k2 -> v2), Map(k3 -> v3))
The desired value for newJsonMap
is:
Map(k1 -> Map(k2 -> v2))
So in a nutshell, I want to convert the value of the k1
key from a List
to a Map
. I first started to implement according to this question: Scala - Flatten a List of Maps to Map
But then I realized that I was dealing with different datatypes, in this case Map[String, Object]
which means I can't perform operations such as using the scala in-built flatten
method to lists.
Is there any way I can convert this Map into a Scala Map so I can apply the necessary transformations to the JSON? Any thoughts on how I should proceed?
Thanks in advance.