-1

in an XML file that uses hyphenated names for XML element Names - i need to convert the xml to JSON so that our webservice project(resteasy) understands the json. i have 1000s of these xml files - i need to find a quick way to automate these conversions.

what library can i use to accomplish this - i tried suggestions here but it didnot help

any suggestions?

example:

input:

<card-transaction xmlns="http://ws.google.com">
      <card-transaction-type>${card-transaction-type}</card-transaction-type>
      <merchant-transaction-id>${merchant-transaction-id}</merchant-transaction-id> 
</card-transaction>

Output:

{
    "merchantTransactionId": "${merchantTransactionId}",
    "cardTransactionType": "${cardTransactionType}"
}
Community
  • 1
  • 1
Narayan
  • 6,031
  • 3
  • 41
  • 45
  • I think this answer may be useful : http://stackoverflow.com/questions/3618733/how-to-convert-do-some-stuff-to-lower-camel-case-dosomestuff-in-the-most-nea – Peter Tillemans Jun 17 '16 at 15:07
  • Sadly, questions on StackOverflow that ask for help finding a library tend to get short shrift from the moderators. SO users are not expected to use libraries, you're expected to write the code yourself (-; – Michael Kay Jun 17 '16 at 16:58
  • @PeterTillemans :i will try those suggestions! – Narayan Jun 17 '16 at 20:08

1 Answers1

1

One approach (there are many others): XSLT 3.0 defines an XML vocabulary that's essentially a direct representation of the JSON you want to generate. Use XSLT to convert the XML into that vocabulary, then press the button (more literally, invoke the xml-to-json() function).

http://www.w3.org/TR/xslt-30/#json

Michael Kay
  • 156,231
  • 11
  • 92
  • 164