Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I generate pretty JSON with json4s?

Tags:

scala

json4s

This snippet of code works very well, but it generates compact JSON (no line breaks / not very human readable).

import org.json4s.native.Serialization.write
implicit val jsonFormats = DefaultFormats

//snapshotList is a case class
val jsonString: String = write(snapshotList)

Is there an easy way to generate pretty JSON from this?

I have this workaround but I'm wondering if a more efficient way exists:

import org.json4s.jackson.JsonMethods._
val prettyJsonString = pretty(render(parse(jsonString)))
like image 718
arosca Avatar asked Aug 24 '16 15:08

arosca


1 Answers

import org.json4s.jackson.Serialization.writePretty

val jsonString: String = writePretty(snapshotList)
like image 98
Michael Pollmeier Avatar answered Nov 02 '22 19:11

Michael Pollmeier