How to Convert XML to JSON

Download lift-json jar from http://scala-tools.org/repo-releases/net/liftweb/

Be sure to grab the proper library for your Scala version, at time of this post the latest was located at http://scala-tools.org/repo-releases/net/liftweb/lift-json_2.8.12.3-RC5/

import net.liftweb.json._
import net.liftweb.json.JsonAST._

val data = xml.XML.loadFile("quotie.xml")
val str = Printer.pretty(render(Xml.toJson(data)))

var out_file = new java.io.FileOutputStream("quotie.json")
var out_stream = new java.io.PrintStream(out_file)

out_stream.print(str)
out_stream.close
About these ads

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s