Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Transformation from XML to JSON

Is there a standard way to transform an input XML document with structure (scheme) of my choice to an output JSON object with structure (scheme) of my choice?

If it were transformation from input XML to output XML, I would use XSLT.

I can image the following three approaches:

  1. Direct transformation from XML to JSON, i.e. a way to describe transformation XML -> JSON just like XSLT describes transformation XML -> XML.

  2. I am aware of JSONML. It is a lossless JSON representation of arbitrary XML document. However, the resulting JSON object does not have the structure of my choice. If there were some standard way to describe transformation JSON -> JSON, I would chain XML -> JSONML and JSONML -> JSON.

  3. If there were the opposite to JSONML (let's call it "XMLSON", i.e. a lossless XML notation of arbitrary JSON object), I would chain XML -> XMLSON (via XSLT) and XMLSON -> JSON.

All the three options have some "if there were". I wonder if there really is some technology to achieve the goal.

Thanks.

like image 542
Cimlman Avatar asked Jan 28 '26 04:01

Cimlman


1 Answers

XSLT 3 has support to transform any XML to an XML representation of JSON defined in https://www.w3.org/TR/xslt-30/#schema-for-json and then allows you to use https://www.w3.org/TR/xslt-30/#func-xml-to-json to convert that particular XML to JSON.

like image 177
Martin Honnen Avatar answered Jan 29 '26 19:01

Martin Honnen



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!