Feature: JSON to XML #58
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This closes issue #43 :
I have implemented the feature to translate JSON to XML. The feature was implemented trying to replicate the one from OnlineTools, as @iib0011 recommended. Apart from that, I still implemented some fixes that the previous one does not acknowledge, for example,
null
values in JSON: it is valid JSON, so it must be converted appropriately.Even though I was recommended to use https://www.npmjs.com/package/json-xml-parse, I think it is not necessary to depend on a package for this, for two reasons:
The implementation is quite straightforward using recursion and since JSON does not have many data types, it is easy to debug and handle all the conversions. Third-party libraries must be used for more complicated features (for example, video and image manipulation), but I think this one does not justify to overload the project with dependencies. This allows us not to lose track of the dependencies in the future. Using
JSON.parse
to parse the JSON to ensure it is valid is enough; the rest seems ok to be implemented manually.The package does not provide options for the indentation (e.g. spaces, tabs or unformatted), which means that I would have to format the resulting XML code after the conversion (according to the user's selection, if it is not the standard formatting), instead of building the XML code the right way from the beginning.
Despite this, if you still wish to use this library, I can change the approach and use it.
Here are some screenshots: