fast-xml-parser icon indicating copy to clipboard operation
fast-xml-parser copied to clipboard

Can we configure the value of empty node to be an empty object instead of empty string while parsing xml

Open qbert-007 opened this issue 3 years ago • 2 comments

Checklist

  • [ ] Have you asked your question on Stackoverflow or similar forum?
  • [x] Are you running the latest version?
  • [x] Have you included sample input, output, error, and expected output?
  • [x] Have you checked if you are using correct configuration?
  • [x] Did you try online tool?

Input

Code

let xmlData = '<any_name></any_name>'
const parser = new XMLParser({});
let jsonObj = parser.parse(xmlData);
console.log(jsonObj)

Output

{"any_name":""}

expected data

{"any_name":{}} Would you like to work on this issue?

  • [x] Yes
  • [ ] No

Bookmark this repository for further updates.

qbert-007 avatar Sep 30 '22 11:09 qbert-007

With the current implementation, No. But we can think about it if more people need the same feature.

amitguptagwl avatar Oct 05 '22 11:10 amitguptagwl

Definitely a much needed feature! It should be {} by default, string breaks the whole idea of types in TypeScript.

nikimicallef avatar Jan 19 '23 09:01 nikimicallef