How to Use HTML Functionality in Retool for JSON to HTML Conversion

1 Like

Hey @Hsiao_Min_Shyh! Welcome back to the community. :slightly_smiling_face:

I don't know if it's exactly the same library, but I'm able to get this one working by updating the "Libraries" list in the app settings as shown below.

image

The following test case then runs as expected:

image

This query generates HTML that I can put directly into an HTML component and display in the app! I hope that helps. :+1: Let me know if you have any additional questions.

Hi Darren, thank you for your reply. This package is a bit different and more specialized. According to the website 在網頁上使用開源專案預覽 LINE Flex 訊息 | 筆記國度, this open-source tool converts JSON messages, specifically the flex messages in the LINE Message API, into HTML.

  1. In the documentation, it suggests adding CSS to the HTML head: <link rel="stylesheet" href="https://cdn.jsdelivr.net/gh/PamornT/flex2html@main/css/flex2html.css">.
  2. Then, add the script to the body: <script src="https://cdn.jsdelivr.net/gh/PamornT/flex2html@main/js/flex2html.min.js">.
  3. In the HTML, set up <div id="flex2html"></div>.
  4. Use flex2html('flex2html', flexJson) to call the function and perform the conversion.

The steps seem simple, but I haven't been able to implement them in Retool. I'm unsure how to use the CSS library and how to correctly call the flex2html function (step 4).

Hi Darren, I successfully used this package with the deprecated customer component. However, I haven't been able to get it to work with the new HTML component version yet.

Basically, I copied the example from GitHub directly, but note that the URL in the head section is slightly different, as shown in Image 1.

I replaced the JSON data using jsoneditor as an example, while the HTML body was pasted directly from GitHub without any changes.

However, since the JSON data may change, I used GPT to help me write a React syntax to test it out, and it worked, as shown in Image 2.

The only issue is that the loading speed is a bit slow.

But switching to the current HTML component, my attempts are still unsuccessful.

You could try ditching React + Babel since it is such a simple component?

Use the vanilla handlers?

Thanks for sharing an update, @Hsiao_Min_Shyh! I'm not surprised that the built-in HTML component doesn't work for this use case, as it has very limited scripting support. This particular library also interacts with the document, meaning an iframe or custom component are probably the only ways to get it working.

If you haven't already, I'd recommend building a custom component using the new library as this is likely to have better performance. :+1: