XML : What is the correct way to format data in JSON if convertibility between data formats is considered?

If the data defined in JSON is subject to conversion to XML (and vice-versa), what is the correct way to format data within? I am primarily concerned about arrays, as my data exchange is based on DataContract serialization, and XML attributes are not supported, thus they are not a problem.

Shall I wrap arrays in a collection element?

  {      "order": {          "customer": 43694,          "items": {              "item": [                  64,                  34,                  98              ]          }      }  }    

Or shall I just leave them out in the open?

  {      "order": {          "customer": 43694,          "item": [              64,              34,              98          ]      }  }    

When converting to XML, these JSON structures yield the following output, respectively; wrapped in a collection element:

  <order>    <customer>43694</customer>    <items>      <item>64</item>      <item>34</item>      <item>98</item>    </items>  </order>    

Left out in the open:

  <order>    <customer>43694</customer>    <item>64</item>    <item>34</item>    <item>98</item>  </order>    

No comments:

Post a Comment