Re: [xsl] Convert JSON to XML?

Subject: Re: [xsl] Convert JSON to XML?
From: "BR Chrisman brchrisman@xxxxxxxxx" <xsl-list-service@xxxxxxxxxxxxxxxxxxxxxx>
Date: Fri, 2 May 2025 12:49:03 -0000
I keep thinking that if there was a standard declaring something like "json
fit for xml" and/or "xml fit for json", at least there would be targets by
which to do this without a lot of the bigger cruft things.
That would require json keys to be valid qnames and for all array
demarcations [] to be named, and possibly some other details.

I noticed that we see these issues in oidc/saml work where at least some
providers will put into their json-web-tokens things like { "role": "foo" }
if there's one role.. but { "role" : [ "foo", "bar" ] } if there are
multiple.  That's makes life difficult... and I presume it's because some
underlying piece in XML looks like '<role name="foo"/><role name="bar"/>'
and there's some automated xml-to-json which has no spec, but rather
transforms any same-named elements into json arrays.  The point of this
example is that there's a spec-type-thing needed to ensure that xml/json
conversion is consistent, rather than just doing-its-best from what it sees
at the moment of conversion.... Not sure how popular it would be to create
a json-fit-for-xml in that fashion.

On Fri, May 2, 2025 at 5:07b/AM Michael B Allen ioplex@xxxxxxxxx <
xsl-list-service@xxxxxxxxxxxxxxxxxxxxxx> wrote:

>
>
> 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?
>>
>
> 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/ <http://www.ioplex.com/>
> XSL-List info and archive <http://www.mulberrytech.com/xsl/xsl-list>
> EasyUnsubscribe <http://lists.mulberrytech.com/unsub/xsl-list/965995> (by
> email <>)

Current Thread