This would be great as it would allow my xml stuff to read json w/out any change except for the different sax parser.
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.
<string>
, <number>
or <array>
markers as it is typed), which neither natural JSON nor natural XML representations of logical content should have. This is exactly what is dubbed franken-JSON (when going from xml to json); in this it is the opposite. There are many such mapping, all as cumbersome and unnatural to use -- but if conversion of any and all content without loss needed, is necessary. So this is a good example of what I mean. –
Chemo 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.
http://rapidjson.org/ ftw. "A fast JSON parser/generator for C++ with both SAX/DOM style API." Industrial-strength, used by TenCent.
© 2022 - 2024 — McMap. All rights reserved.