Is there a SaxParser that reads json and fires events so it looks like xml Is there a SaxParser that reads json and fires events so it looks like xml xml xml

Is there a SaxParser that reads json and fires events so it looks like xml


If you meant, event-based parser then there are a couple of projects out there that do this:

  1. http://code.google.com/p/json-simple/

    Stoppable SAX-like interface for streaming input of JSON text

    This project has moved to https://github.com/fangyidong/json-simple

  2. http://jackson.codehaus.org/Tutorial

    Jackson Streaming API is similar to Stax API

    This project has moved to https://github.com/FasterXML/jackson-core


I think it is a bad idea to try treat JSON as if it was XML (which is what you are essentially asking); however, Jettison does just this. It exposes JSON content via Stax API (javax.xml.stream). And if you truly want SAX, writing wrapper from Stax to SAX is trivial as well (but not the other way around).

I also think you might get better answers if you explained bit more what you are trying to achieve, beyond mechanisms you are hoping to use. For example, there are many data binding tools for both XML and JSON; and using such tools could hide lower level details much better than using abstraction meant for one to process the other.


I have developed a streaming StAX-based converter: https://github.com/AtomGraph/JSON2XML

It reads any JSON data and produces XML Representation of JSON specified in XSLT 3.0.

JSON2XML enables JSON transformation with XSLT even without having an XSLT 3.0 processor. You can simply pre-process the data by having JSON2XML before the transformation, and pipeline it into an XSLT 2.0 stylesheet, for example. That way your stylesheet stays forward compatible with XSLT 3.0, as the XML representation is exactly the same.

Feedback and pull requests are welcome.