How to convent json to html by this plugin?
Closed this issue · 3 comments
@yousufkalim How to convent json to html by this plugin?
or do you plan to add this function?
Dear @winds1983,
Thank you for reaching out and for your suggestion. I'm glad to hear that you are interested in the plugin and its potential to convert JSON to HTML.
Unfortunately, at this time, the plugin does not have this capability. However, I appreciate your suggestion and I will certainly keep it in mind for future development. I will let you know if this feature is added in the future.
Best regards, Yousuf Kalim
Update
Hey @winds1983, I'm really busy these days in other projects. However I can give you the code that will convert the JSON response again to an HTML Element.
You can use this code and update according to your preferences.
function JSONToHTMLElement(content: JSONContent): HTMLElement {
const element = document.createElement(content.type);
if (content.attributes) {
Object.entries(content.attributes).forEach(([attribute, value]) => {
element.setAttribute(attribute, value);
});
}
if (content.content) {
content.content.forEach((node) => {
if (typeof node === 'string') {
element.innerHTML += node;
} else {
element.appendChild(JSONToHTMLElement(node));
}
});
}
return element;
}
If you get this code working then please do a help to other developers by contributing to this library and by keeping contribution guidelines in mind that I've mentioned in the README.md file.
Thank you so much
Best regards, Yousuf Kalim
Feature announcement
Hey @winds1983 ,
I've added the feature to convert JSON/Object to HTML in the latest version of the library. You can now use the JSONToHTML
method to easily convert JSON/Object data to HTML. Please visit the Readme for detailed guide.
Let me know if there's anything else I can help with.
Best regards.