Reputation: 3256
Is there an easy way to convert List[String] to String format with "
and ,
. For example
val fruits: List[String] = List("Apple", "Banana", "Grapes", "Pears")
==> "Apple", "Banana", "Grapes", "Pears"
I want to do this because I have to append the result in JSON string.
{
....,
"fruits": ["Apple", "Banana", "Grapes", "Pears"],
....
}
Upvotes: 0
Views: 3050
Reputation: 25939
fruits.mkString("\"fruits\": [\"", "\",\"", "\"]")
but I'd use something like https://github.com/circe/circe instead of building JSONs myself
Upvotes: 6