How to import data with JSON?

What is the most widespread or standardized convention for converting data between XML and JSON?

  • There are several different conventions for mapping data between XML and JSON. Some are lossy and some are lossless. Lossy methods don't convert all XML data structures to JSON while lossless methods can convert all data back and forth between either format. The lossy methods have the advantage that the JSON is more lean while the lossless methods have the advantage of being more of a fully equivalent representation of the data in either format. Several different conventions for mapping between each format have been proposed, but none seem to be dominant or seen as any kind of standard. These conventions include Badgerfish, Parker, JsonML, gData, Abdera, and others. These are outlined at http://wiki.open311.org/JSON_and_XML_Conversion Which conventions are recognized as the most preferable or standardized by developers and what are some good examples of where that convention is in widespread use?

  • Answer:

    Developers that consume XML usually have different motivations and expectations than developers that consume JSON. It might be useful for us to explore what is expected by a seasoned XML or JSON developer when he comes across a new XML or JSON API. Some that come to mind (feel free to chime in): JSON terse key names, compact structure no namespaces minimally nested objects simple types (string, number, boolean, array, object, rfc3339 datetime) parseable easily in a web browser XML supports namespaced parsing workflows good when you need lots of metadata and tags In light of these differences it might not make sense to try and programatically port XML to JSON. Thoughtful design needs to be implemented in order to take one and turn it into another. Instead of having all of the information in each representation, a better approach might be to selectively remove or add information based on your audience. You can always add a separate metadata REST endpoint to your API if you find that you are taking useful data out of the JSON representation of something. Here are some explorations of this idea: https://gist.github.com/859230

Max Ogden at Quora Visit the source

Was this solution helpful to you?

Other answers

I wanted to update this thread by mentioning that we decided on a slight  modification of the Parker convention which we're calling the Spark convention for the JSON support in the Open311 GeoReport API: http://wiki.open311.org/JSON_and_XML_Conversion#The_Spark_Convention

Philip Ashlock

Related Q & A:

Just Added Q & A:

Find solution

For every problem there is a solution! Proved by Solucija.

  • Got an issue and looking for advice?

  • Ask Solucija to search every corner of the Web for help.

  • Get workable solutions and helpful tips in a moment.

Just ask Solucija about an issue you face and immediately get a list of ready solutions, answers and tips from other Internet users. We always provide the most suitable and complete answer to your question at the top, along with a few good alternatives below.