Rodion Gorkovenko
Rodion Gorkovenko

Reputation: 2852

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:

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.

Upvotes: 6

Views: 1206

Answers (3)

Ryan Gibbons
Ryan Gibbons

Reputation: 3601

Yes it possible. I think all your concerns could be handled cleaning if you defined how they are to be processed. I don't know of a standard way of doing it.

I think this is very telling in how you would need to go about it http://jsontoxml.utilities-online.info/

Basically You'd "encode" attributes and text data with a way to signify what's data, what's an attribute, etc. Pretty intresting and I think playing with this tool will give you some ideas of out to create a ruleset that will work for you specifications.

Biggest thing if you go forward with this is to document how the processing works and what is expected.

Upvotes: 0

jayunit100
jayunit100

Reputation: 17648

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).

Upvotes: 1

Mitchel Sellers
Mitchel Sellers

Reputation: 63126

Personally a lot of this is going to really depend on your specifics for implementation. But in the end, the real key should be in the actual relationships that you have...

  • Object -> JSON
  • JSON -> Object
  • Object -> XML
  • XML -> Object

As really doing anything that tried to do an arbitrary conversion from XML -> JSON or vice-versa would be really hard to manage/process as you outline. But if you have a common object model in the middle, you should be fine.

Therefore, as long as your Serialization and Deserialization methods work for the respective object types, the actual processes should not have any issues.

Upvotes: 0

Related Questions