-
Notifications
You must be signed in to change notification settings - Fork 606
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
json/ js to xml conversion looses empty arrays information #398
Comments
I have fixed it using below code, using JavaScript, writing fix details below, because I don't know Coffee Script to create pull-request, if fix is good in general too, then please help others via a pull request: Fix detailsin the file: .\xml2js\lib\builder.js below code:
should be changed to:
|
Good point. Please send this as pull request.
|
Oh, I didn't see your message. Well, I can only apply it when I have some spare time. |
I'm not sure this needs a fix in xml2js. If you want an empty element in your XML, just add an empty string to your array: let jsonObj = {
key1: 'val2',
arrayKey1: [456],
emptyKey1: '',
emptyArrayKey1: ['']
};
var builder = new xml2js.Builder();
var xml = builder.buildObject(jsonObj);
console.log(xml); Output: <?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<root>
<key1>val2</key1>
<arrayKey1>456</arrayKey1>
<emptyKey1/>
<emptyArrayKey1/>
</root> |
json/ js to xml conversion looses empty arrays information
An empty string is converted to an empty tag.
An empty array is Not converted to an empty tag.
However, we needed for our functionality so that clients don't break, for example, when card numbers are not given, an empty tag exists
example:
actual output (NOTE: emptyArrayKey1 tag is missing):
expected output (NOTE: emptyArrayKey1 tag is now back):
The text was updated successfully, but these errors were encountered: