I have a need of transforming various message formats into JSON and v.v., e.g. XML to JSON and then JSON to XML or EDI to JSON and JSON to EDI.
I've looked at several different XML-to-JSON modules and they seem mostly to be into a direct conversion into their own JSON and/or XML format and not into my required XML (e.g. UBL 2.1).
One easy straight forward way of going about it is to just use a String variable:
let myXML = '<root><hdr>' + jsonIn.hdr + '</hdr>\r\n';
myXML += '<itm>' + jsonIn.item[0] + '</hdr></root>';
The myXML
variable will be quite big though. Up to 200 kB currently but can grow bigger in the future.
Obviously this is the quickest and easiest way of creating the outbound formats but it doesn't really feel right to create a massive String variable...
In Java I'd use StringBuilder and there is a npm for Node: https://www.npmjs.com/package/stringbuilder
Which approach would you consider the "best practice" approach?