Skip to content

Instantly share code, notes, and snippets.

@jabley
Created March 15, 2012 14:28
Show Gist options
  • Save jabley/2044466 to your computer and use it in GitHub Desktop.
Save jabley/2044466 to your computer and use it in GitHub Desktop.
How to pretty print a large json document
:cp /Users/jabley/.m2/repository/com/google/code/gson/gson/2.1/gson-2.1.jar
import java.io.{OutputStreamWriter, FileOutputStream, FileReader}
import com.google.gson.{GsonBuilder, JsonParser}
val gson = new GsonBuilder().setPrettyPrinting().create()
val json = new JsonParser().parse(new FileReader("get-menu-and-start-order.json"))
val fos = new FileOutputStream("get-menu-and-start-order.pretty.json")
val writer = new OutputStreamWriter(fos)
gson.toJson(json, writer)
writer.flush()
fos.getFD().sync()
writer.close()
@jabley
Copy link
Author

jabley commented Mar 15, 2012

online tools didn't like the size of the document that I'm playing with. I can't say I care for it much myself!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment