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"],
....
}
s""""${fruits.makeString(", ")}""""But what if some of the values contain double quotes? Crafting json "by hand" is actually, suprisingly harder than it looks. So, better, do something standard, likeJackson.mapper.writeValueAsString(fruits).