Supposing that you have data like
val data = Map("test" -> 113123, "cat" -> None, "myList" -> Map("test2" -> 321323, "test3" -> 11122))
//data: scala.collection.immutable.Map[String,Any] = Map(test -> 113123, cat -> None, myList -> Map(test2 -> 321323, test3 -> 11122))
Then you can do
val output = data.map(x => if (x._2.isInstanceOf[Map[String, Long]]) (x._1 -> Some(x._2)) else x)
//output: scala.collection.immutable.Map[String,Any] = Map(test -> 113123, cat -> None, myList -> Some(Map(test2 -> 321323, test3 -> 11122)))
to get your desired output
And you can use println
to see the output
as
println(output)
//Map(test -> 113123, cat -> None, myList -> Some(Map(test2 -> 321323, test3 -> 11122)))