Subject: Re: [xsl] Convert JSON to XML? From: "dvint dvint@xxxxxxxxx" <xsl-list-service@xxxxxxxxxxxxxxxxxxxxxx> Date: Fri, 2 May 2025 16:54:44 -0000 |
I'm trying to find an xml result that is better than what json-to-xml() produces. I already have that approach working. I'm not trying for the perfect or correct interpretation of the json environment,B just something with more useful element names. Was that the map/map/map/string item, vs example/titleSent from my Verizon, Samsung Galaxy smartphone -------- Original message --------From: "Edward Porter edward.porter@xxxxxxx" <xsl-list-service@xxxxxxxxxxxxxxxxxxxxxx>IDate: 5/2/25 6:02 AM (GMT-08:00) To: xsl-list@xxxxxxxxxxxxxxxxxxxxxx Subject: Re: [xsl] Convert JSON to XML? Regarding bloading into a Docker image for the production implementationb, last year I presented at XML Prague 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 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. B B On Thu, May 1, 2025 at 6:35b/PM dvint@xxxxxxxxx <xsl-list-service@xxxxxxxxxxxxxxxxxxxxxx> 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? B Hi Dan, B 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> B <street>123 Main St</street> B <city>Townville</city> B <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 B street="123 Main St" B city="Townville" B 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. B Mike B -- Michael B Allen Java AD DS Integration https://www.ioplex.com/ XSL-List info and archive EasyUnsubscribe (by email) XSL-List info and archive EasyUnsubscribe (by email) XSL-List info and archive EasyUnsubscribe (by email)
Current Thread |
---|
|
<- Previous | Index | Next -> |
---|---|---|
Re: [xsl] Convert JSON to XML?, Edward Porter edward | Thread | Re: [xsl] Convert JSON to XML?, Martynas Jusevičius |
Re: [xsl] Convert JSON to XML?, Dave Pawson dave.paw | Date | Re: [xsl] Convert JSON to XML?, Martynas Jusevičius |
Month |