This would be great as it would allow my xml stuff to read json w/out any change except for the different sax parser.
JSON is Unlike XML BecauseXML has to be parsed with an XML parser. JSON can be parsed by a standard JavaScript function.
SAX (Simple API for XML) is an event-based parser for XML documents. Unlike a DOM parser, a SAX parser creates no parse tree.
If you meant, event-based parser then there are a couple of projects out there that do this:
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
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With