Skip to content

Conversation

lfsjesus
Copy link
Contributor

@lfsjesus lfsjesus commented Mar 26, 2025

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:

  1. 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.

  2. 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:

image
image
image

@lfsjesus lfsjesus marked this pull request as draft March 26, 2025 15:18
@lfsjesus lfsjesus marked this pull request as ready for review March 26, 2025 15:52
@iib0011 iib0011 merged commit c3023ae into iib0011:main Mar 26, 2025
3 checks passed
@iib0011
Copy link
Owner

iib0011 commented Mar 27, 2025

Thank you @lfsjesus

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants