nashwaan / xml-js

Converter utility between XML text and Javascript object / JSON text.
MIT License
1.26k stars 180 forks source link

XML-JS Empty xml files being made after conversion from .json file #201

Open elnot117 opened 1 year ago

elnot117 commented 1 year ago

I'm currently using "yarn" to issue my command instead of npm. After using xml-js to convert my files, it makes the xml file but does not retain the information within the .json file. Command Prompt Line used:

yarn xml-js C:\Users\Solis_a\Selenium-Tests\results-2023-06-27T13-31-20.567Z.json --spaces 4 --out C:\Users\Solis_a\Selenium-Tests\results-2023-06-27T13-31-20.567Z.xml

Am I entering the line improperly or is it a file issue?

matthew-ia commented 10 months ago

I had the same issue: no output from a JSON->XML run, and no errors logged. Although, I'm not sure that is necessarily a problem with this package (although, an error or hint of some kind would be nice, when there is empty output).

I figured out my issue, which was that my input JSON was incorrectly structured. I used the CLI to validate manually by giving it good, expected XML, and got JSON out. I then compared the good JSON (expected) to my JSON (actual) and was able to find my structural errors. Specifically, my issue was that I mixed compact and non-compact in my JSON, which caused the empty output without errors—it seems that there are allowed/expected keys in non-compact that will just cause the parsing to break (understandably).

It would be cool if this package offered validation tooling, but I can see how that might fall out of scope for this package, especially if the "non-compact" and "compact" structures are standards. (I'm a bit unfamiliar with the XML <-> JS tooling, but after reading the README I expect those structures are sort of common or standards across similar APIs/tools?)