Newtonsoft converting Json Array to XML

Started by spl, March 08, 2024, 04:41:31 AM

Previous topic - Next topic

spl

This is probably off-topic for most, and if so, read no further... otherwise an FYI

Creating a Json file, especially from a db table or API return will format as a json Array [see attached athletes.txt, renamed from .json in order to attach]... the file begins with "[".

The Newtonsoft Json .dll which is used for serialization and conversion is an accepted standard for json activities. One in particular which I worked with was the DeserializeXNode() method which converts Json=>XML. The problem is the method requires a "root" element or calling the method will error.

Using "root" as a name for the element in this case to avoid the error I wrote code to modify the original Json [see attached athletes_1.txt]

Then I got correct XML [see attached athletesXML.txt].

I have personal interest in the conversion as json dates are converted to ISO dates with Newtonsoft.
Stan - formerly stanl [ex-Pundit]