I am getting the following result from converting xml to JSON, using more than one conversion library. As you can see, the property name attributes are lost, as are the Item name attributes. Why?
Does anyone have recommendations on how I might change my XML to make it more conversion friendly?
<Asset name="xyz">
<Property name="p1">Value 1</Property>
<Property name="p2">Value 2</Property>
<TimeSeries name="TimeSeries Name 1">
<Item name="30 Apr 2009">97.47219</Item>
<Item name="01 May 2009">97.16496</Item>
<Item name="05 May 2009">97.34606</Item>
</TimeSeries>
</Asset>
Retuns
{"Asset":{"@attributes":{"name":"xyz"},
"Property":["Value 1","Value 2"],
"TimeSeries":{"@attributes":{"name":"TimeSeries Name 1"},
"Item":["97.47219","97.16496","97.34606"]}}}
I have tried the following, but both the XML and JSON are a lot more verbose:
<Asset name="xyz">
<Property><name>p1</name><value>Value 1</value></Property>
<Property><name>p2</name><value>Value 2</value></Property>
<TimeSeries name="TimeSeries Name 1">
<Item><date>30 Apr 2009</date><value>97.47219</value></Item>
<Item><date>01 May 2009</date><value>97.16496</value></Item>
<Item><date>05 May 2009</date><value>97.34606</value></Item>
</TimeSeries>
</Asset>
resulting in...
{"Asset":{"@attributes":{"name":"xyz"},
"Property":[{"name":"p1","value":"Value 1"},{"name":"p2","value":"Value 2"}],
"TimeSeries":{"@attributes":{"name":"TimeSeries Name 1"},
"Item":[{"date":"30 Apr 2009","value":"97.47219"},
{"date":"01 May 2009","value":"97.16496"},{"date":"05 May 2009","value":"97.34606"}]}}}