Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Are there strict rules for conversion JSON to XML and back?

Are there any strict rules for conversion between JSON and XML?

Program I am working on should be able to output results in both formats, but among all the possible conversion utilities, libraries etc. I could not understand if there are any standard (possibly, "de-facto") for this conversion.

Common problems, as I see, are:

  • conversion from one format to other and then back should give result identical to original;

  • JSON have arrays - simple nesting of similar child items in the XML would not do, since some XML-processing tools would not preserve the order;

  • XML have attributes - their representation as a child items would change original XML when converting back.

Can I found any documentation on this question - or I may use any suitable converter because the lack of such standard?

Thank you in advance for links, advices, guides.

like image 806
Rodion Gorkovenko Avatar asked Dec 14 '11 04:12

Rodion Gorkovenko


1 Answers

No... There is no strict rule as of yet.

As you imply... Although JSON can be converted to XML, the conversion cannot be robust , because XML tag lists are not, by definition, coupled to any particular data structure, where as JSON data structures are (maps and lists). Thus... JSON files , if converted to XML, cannot be losslessly converted back to JSON (unless of course you embed some nonstandard meta information in the JSON objects which are used for the XML decoding).

like image 96
jayunit100 Avatar answered Nov 18 '22 20:11

jayunit100