I must convert XML document to JSON format with skipping specified keys and appending its values to parents. I'm forced to use Java 7. For example I have following XML and I must skip "message" elements:
<messages>
<message>1</message>
<message>2</message>
<message>3</message>
<message>4</message>
</messages>
Expected output is:
{
"messages" : [
1,
2,
3,
4
]
}
I'm using XML.toJSONObject(xmlInput) from org.json library to convert xml to jsonObject. Then I tried to convert jsonObject to expected output in two ways:
a) by using jsonPointer - I failed because I did not have access to parent element
b) by manipulating resulted json with regular expressions - I failed because it seemed very complicated
Do you have any idea how to do it?