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.1/2.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

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>