Before I begin, I have read many posts/topics here/on the internet, but as far as I understand, I think none of the solutions I saw can deal with this JSON
I have a JSON file which I am looking to convert into an XML file - the catch is, when converting to XML normally, JSON like this -
{
"data": {
"key4":{
"sample8": [
{
"sample9":"val",
"sample10":"val"
},
{
"sample11":"val",
"sample12":"val"
},
{
"sample13":"val",
"sample14":"val"
}
]
}
}
}
becomes -
<?xml version="1.0"?>
<data>
<key4>
<sample8>
<sample9>val</sample9>
<sample10>val</sample10>
</sample8>
<sample8>
<sample11>val</sample11>
<sample12>val</sample12>
</sample8>
<sample8>
<sample13>val</sample13>
<sample14>val</sample14>
</sample8>
</key4>
</data>
But, what I am looking to do is create a container element in the XML for every JSON array, with a specific array item element name (like "item"). Here's an example of the XML result I want -
<?xml version="1.0"?>
<data>
<key4>
<sample8>
<item>
<sample9>val</sample9>
<sample10>val</sample10>
</item>
<item>
<sample11>val</sample11>
<sample12>val</sample12>
</item>
<item>
<sample13>val</sample13>
<sample14>val</sample14>
</item>
</sample8>
</key4>
</data>
How do I do this? As I said, I've tried many different things but nothing seems to work out for me... Kindly guide :) Thanks!
P.S. If PHP doesn't support this kind of conversion, I'll be okay to use any other language which supports doing something like this.