DefinitelyTyped/xml2json/xml2json-tests.ts
Dolan 2a888886b1 Typings for xml2json (#13711)
* typings for xml2json

* carried out suggestions made by andy-ms

* fixed: 9:1 unified-signatures  These overloads can be combined into one signature taking `{} | string`.
2017-01-04 06:25:46 -08:00

25 lines
520 B
TypeScript

import * as parser from 'xml2json'
var xml = "<foo attr=\"value\">bar</foo>";
// xml to json
var jsonString: string = parser.toJson(xml);
// json to xml
var xml: string = parser.toXml(jsonString);
// xml to json in object mode and JsonOptions
var jsonObject: Object = parser.toJson(xml, {
object: true,
reversible: false,
coerce: false,
sanitize: true,
trim: true,
arrayNotation: false
});
// json to xml with XmlOptions
var xml: string = parser.toXml(jsonObject, {
sanitize: true
});