Subject: Re: [xsl] Convert JSON to XML? From: "Edward Porter edward.porter@xxxxxxx" <xsl-list-service@xxxxxxxxxxxxxxxxxxxxxx> Date: Fri, 2 May 2025 13:02:00 -0000 |
Regarding bloading into a Docker image for the production implementationb, last year I presented at XML Prague<https://www.xmlprague.cz/day2-2024/#Containerizing> on containerizing XML build tools. You might try that path. You could easily build an image with Saxon and an XProc processor (like MorganaXProc), and the JVM of your choice. With those tools in place, you could write a pretty simple XProc pipeline to leverage the XSLT fn:json-to-xml<https://www.saxonica.com/documentation12/index.html#!functions /fn/json-to-xml> to generate XML from your JSON inputs. If you pipelinebs simple enough, you may be able to skip the XProc processor itself and just use Saxon directly. You can create the image such that itbs effectively a CLI tool rather than a continuously running container by mounting the appropriate input and output volumes and configuring the parameters you need to pass to your pipeline in your dockerfile. On Thu, May 1, 2025 at 6:35b/PM dvint@xxxxxxxxx<mailto:dvint@xxxxxxxxx> <xsl-list-service@xxxxxxxxxxxxxxxxxxxxxx<mailto:xsl-list-service@xxxxxxxxxxxx rytech.com>> wrote: I know (and have been using) the xlst json-to-xml() function for this purpose, but it is a pretty basic result. I happened to try the JSON to XML funtion in oXygen and got what I'd say is a much better result where I had some unique elemeent names instead of everything being a map or a string element. I was poking around to try and find a tool/library I could use in my conversion path and everything I'm finding is an online tool or has a price. Currently I'm developing a conversion pipeline and can leverage oXygen for this, but I need something I can build into a tool and load into a Docker image for the production implementation. Anyone have a suggestion? Hi Dan, It is not possible to map JSON to XML in a "correct" way because a JSON element can only be either a map or a list and not both whereas each XML element is both a map and a list. As a result there are many ways to represent the same data. And frequently what is perceived as "correct" is really not technically or conceptually. For example, it is commonplace to do something like the following: <address> <street>123 Main St</street> <city>Townville</city> <state>PA</state> </address> IMO the "correct" form for an XML element is to put values that are not divisible into attributes which means the truely correct way to represent this data is: <address street="123 Main St" city="Townville" state="PA"/> Anyway, my point is that the only "correct" way to convert JSON to XML is to understand in advance which of the many XML representations is "correct" for your particular application and then write code to explicitly perform that conversion. It's also not something that necessitates a third party tool as it is almost trivial to write code to recur through the JSON structure and emit XML text directly. Mike -- Michael B Allen Java AD DS Integration https://www.ioplex.com/<https://protect.checkpoint.com/v2/r01/___http://www.i oplex.com/___.YzJ1OnNhc2luc3RpdHV0ZTpjOm86OTY4MWMzZGU5NGVlY2VlYzkzZDUyNzk5Y2R lY2UzMTc6NzpmZDBhOjZjNGM1MjI2ODIzNTBiYTc5N2U2YmRlYTlkYWY2OGYxZDU3Yzk2ZTE0NjE3 NzkyODhmNWIzNTAyNzgzNGI5ZWE6aDpUOk4> XSL-List info and archive<https://protect.checkpoint.com/v2/r01/___http://www.mulberrytech.com/ xsl/xsl-list___.YzJ1OnNhc2luc3RpdHV0ZTpjOm86OTY4MWMzZGU5NGVlY2VlYzkzZDUyNzk5Y 2RlY2UzMTc6Nzo4YTg1OmM2OGU2NDdlN2VjMTAwZTkwMmE3N2MwZDY2N2FhMjhjNDI4OTliNGI0ZD AzNzcxOGY3YWNhNzMxYTE5NjMzNGI6aDpUOk4> EasyUnsubscribe<https://protect.checkpoint.com/v2/r01/___http://lists.mulberr ytech.com/unsub/xsl-list/965995___.YzJ1OnNhc2luc3RpdHV0ZTpjOm86OTY4MWMzZGU5NG VlY2VlYzkzZDUyNzk5Y2RlY2UzMTc6Nzo0ZDMzOmM5NmFhZjM5NjI0MjM1YTUxZmFiZGExN2RhZWR jMDVhY2QwZTQ4ZGY1MGI2YzMyNWM1ZTc5M2NiYTc5ZmUwNDE6aDpUOk4> (by email) XSL-List info and archive<https://protect.checkpoint.com/v2/r01/___http://www.mulberrytech.com/ xsl/xsl-list___.YzJ1OnNhc2luc3RpdHV0ZTpjOm86OTY4MWMzZGU5NGVlY2VlYzkzZDUyNzk5Y 2RlY2UzMTc6NzplYjRkOmIwMTk3YzM1ZTJhYTY3OWI1MjM2NDM1M2YwOWI1MWRjOWExMjY4ZjY4NG E1MDE2YmU1MGRjMmYxM2FlZDNkNjE6aDpUOk4> EasyUnsubscribe<https://protect.checkpoint.com/v2/r01/___http://lists.mulberr ytech.com/unsub/xsl-list/3195664___.YzJ1OnNhc2luc3RpdHV0ZTpjOm86OTY4MWMzZGU5N GVlY2VlYzkzZDUyNzk5Y2RlY2UzMTc6Nzo1ZTEwOjlkN2RjYjY1ZTI4YjBjODg1ODgwNzZhNzg1MD ZhYzUyNzA0NzI5MWQ4YmJkNGNhZjUwMDdmMGExMmZiYWY1OTE6aDpUOk4> (by email<>)
Current Thread |
---|
|
<- Previous | Index | Next -> |
---|---|---|
Re: [xsl] Convert JSON to XML?, BR Chrisman brchrism | Thread | Re: [xsl] Convert JSON to XML?, dvint dvint@xxxxxxxx |
Re: [xsl] Convert JSON to XML?, BR Chrisman brchrism | Date | Re: [xsl] Convert JSON to XML?, Peter Flynn peter@xx |
Month |