Convert XML to JSON (and back) using Javascript

后端 未结 12 1356
Happy的楠姐
Happy的楠姐 2020-11-22 03:18

How would you convert from XML to JSON and then back to XML?

The following tools work quite well, but aren\'t completely consistent:

  • xml2json
12条回答
  •  终归单人心
    2020-11-22 03:50

    Here' a good tool from a documented and very famous npm library that does the xml <-> js conversions very well: differently from some (maybe all) of the above proposed solutions, it converts xml comments also.

    var obj = {name: "Super", Surname: "Man", age: 23};
    
    var builder = new xml2js.Builder();
    var xml = builder.buildObject(obj);
    

提交回复
热议问题