I want to print json to string in one line.
case class Data(e: Option[String])
object Data {
implicit val dEncoder = deriveDecoder[Data]
implicit val dDecoder = deriveEncoder[Data]
}
case class Random(a: String,b: String, c: Int,d: Data)
object Random {
implicit val rEncoder = deriveDecoder[Random]
implicit val rDecoder = deriveEncoder[Random]
}
val res = Random("a","b", 1, Data("e"))
when i do res.asJson.toString, i get:
{
"a": "a",
"b": "b",
"c":1,
"d":
{
"e": "e"
}
}
but i want it to be printed in one line without \n as using circe.
**{"a": "a","b": "b", "c": 1,d:{"e": "e"}}**
If you don't mind stripping other unnecessary whitespace characters:
@ res.asJson.noSpaces
res9: String = "{\"a\":\"a\",\"b\":\"b\",\"c\":1,\"d\":{\"e\":\"e\"}}"
@ println(res.asJson.noSpaces)
{"a":"a","b":"b","c":1,"d":{"e":"e"}}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With