What's the best JSON or JS object to XML converter module for Node JS
I investigated myself
| author | davidcalhoun | soldair | QuickenLoans | michaelkourlas |
|---------------|--------------|-----------|--------------|----------------|
| module | jstoxml | node- | node- | node- |
| | | jsontoxml | easyxml | js2xmlparser |
| Commits | 31 | 64 | 39 | 61 |
| Recent commit | a year ago | 2 years ag| 6 months ago | 16 days ago |
| Contributors | 2 | 7 | 7 | 6 |
| Issues | 16 | 19 | 17 | 15 |
| Open Issues | 7 | 1 | 6 | 1 |
| npm install | jstoxml | not found | easyxml | js2xmlparser |
| Dependencies | None | None | elementtree, | None |
| | | | inflect | |
| Throws errors | None | None | 3 | 12 |
Then there's the type of objects required to compare
{
"_name": 'foo',
"_content": 'bar',
"_attrs": {
"a": 'b',
"c": 'd'
}
}
soldair/node-jsontoxml: looks complicated
items: [{
"name": 'one',
"_id": 1
}, {
"name": 'two',
"_id": 2
}
]
michaelkourlas/node-js2xmlparser
foo: {
"#": 'bar',
"@": {
a: 'b',
c: 'd'
}
}
I think I'll give michaelkourlas's node-js2xmlparser a shot.
Update: It seems now that there are 2 more worth mentioning:
The latter is by far the most matured and downloaded on npm. It allows you to build XML in one go or iteratively.
Related videos on Youtube
Christiaan Westerbeek
For about 20 years I have been helping businesses by understanding their needs and use cases and to build them web apps. All the while I was trying to make the latter part of my job one that is more efficient and enjoyable by creating more value in less time while using open-source libraries. In an ever evolving environment where SaaS-platforms are getting better and better, my journey now led me to a point where I believe that for most business applications we don't even need code anymore, most of the time. I'm here to challenge myself and businesses in a quest for the best solutions out there with little time and resources at hand to see if we can evolve the user landscape with apps built with no-code.
Updated on October 15, 2020Comments
-
Christiaan Westerbeek over 3 years
I need to build a relatively simple XML document with some hierarchy and some attributes from a JS object. I stand now before choosing one of these modules:
- https://github.com/davidcalhoun/jstoxml
- https://github.com/soldair/node-jsontoxml
- https://github.com/QuickenLoans/node-easyxml
- https://github.com/michaelkourlas/node-js2xmlparser
Which module should I pick?
This question will probably be dismissed as being not a good question, but I don't know how to ask it any differently.
Disclaimer: I posted the same question as an issue on each repository
This is the XML that I want to build:
<?xml version="1.0" encoding="UTF-8"?> <orders> <order> <order_orderid>123123</order_orderid> <order_customerid>345345</order_customerid> <order_senhcode>7604</order_senhcode> <order_mediacode>qwert</order_mediacode> <order_totalshippingcost>0</order_totalshippingcost> <order_paymentmethod>GB</order_paymentmethod> <order_paymentnumber /> <order_htmltext /> <order_comment /> <shippingmethodid>02</shippingmethodid> <order_creditcardnumber /> <order_creditcardnameholder /> <order_creditcardexpiredate /> <order_creditcardsafetycode /> <order_gifttext /> <inv_customer> <inv_customer_addresstypeid /> <inv_customer_gendermale>0</inv_customer_gendermale> <inv_customer_firstname>qwerty</inv_customer_firstname> <inv_customer_initials>Q.W.E</inv_customer_initials> <inv_customer_prename /> <inv_customer_lastname>Qwerty</inv_customer_lastname> <inv_customer_company>Some company</inv_customer_company> <inv_customer_street>Postbus</inv_customer_street> <inv_customer_housenumber>13</inv_customer_housenumber> <inv_customer_housenumberadditional /> <inv_customer_postalcode>1234 AB</inv_customer_postalcode> <inv_customer_city>THERE</inv_customer_city> <inv_customer_isocodecountry>NL</inv_customer_isocodecountry> <inv_customer_email>[email protected]</inv_customer_email> <inv_customer_telephone>0168-123456</inv_customer_telephone> <inv_customer_mobilenr>06-12345678</inv_customer_mobilenr> </inv_customer> <orderlines> <orderline> <orderline_orderrecordid>1234</orderline_orderrecordid> <orderline_orderid>8765432</orderline_orderid> <orderline_articlenr>164-05-366</orderline_articlenr> <orderline_quantity>2</orderline_quantity> <orderline_productdescription>Some gift voucher</orderline_productdescription> <orderline_price>1233</orderline_price> </orderline> <orderline> <orderline_orderrecordid>5678</orderline_orderrecordid> <orderline_orderid>8765432</orderline_orderid> <orderline_articlenr>164-05-367</orderline_articlenr> <orderline_quantity>3</orderline_quantity> <orderline_productdescription>Some other gift voucher</orderline_productdescription> <orderline_price>1244</orderline_price> </orderline> </orderlines> </order> </orders>
-
adeneo almost 10 yearsIf it's simple and the key names are given, why not just do it yourself ?
-
Adriano Repetti almost 10 yearsIMO if you don't have any special request then pick smallest one. Try if it works for you and then live happy with that.
-
Christiaan Westerbeek almost 10 years@adeneo because it's better to reuse code that has more contributors and are depended by other projects too. I should not reinvent wheels. Even for simple stuff, because requirements always augment later.
-
adeneo almost 10 yearsWell, that's up to you, I would just write something that fits whatever I need. If you look at the modules you've listed they are all very simple, it's just a recursive loop putting keys and values from JSON in XML tags.
-
Ingmars almost 10 years@ChristiaanWesterbeek You are wrong. I'm with adeneo unless you provide more info on your specific case.
-
Christiaan Westerbeek almost 10 yearsI provided the specific use case
-
Matthew Bakaitis almost 10 yearsThe XML you want to build is related, but picking a module has more to do with how each module fits your coding style, if it meets your requirements (do you need validation? do they report errors? callbacks vs promises? etc), and so on...
-
Christiaan Westerbeek almost 10 yearsI added an answer myself that is trying not to be opinionated by comparing objectively.
-
Redsandro over 8 yearsThank you for this post. I would also find it interesting to see which modules are blocking (most of them) and which ones actually use a callback to call back with the result. Any opinion on that?
-
AF7 almost 4 years
xmlbuilder
is now deprecated in favour ofxmlbuilder2
.