"Convert JSON to HTML" can mean different things depending on your goal: displaying data as a table, embedding formatted JSON as a code block, or rendering a tree view. Here are the best free methods for each use case.
Method 1: JSON → HTML Table (Most Common)
If your JSON is an array of objects (like API response data), converting it to an HTML table is the most useful output.
- Convert the JSON to CSV first using the JSON to CSV tool.
- Copy the CSV output.
- Open the CSV to HTML Table converter.
- Paste the CSV data and click Convert.
- Copy the generated HTML table code — it includes
<thead>with headers and<tbody>rows. - Paste into your HTML file.
Method 2: JSON as a Formatted Code Block in HTML
To display JSON as readable code on a webpage (for documentation or debugging):
<pre><code id="json-display"></code></pre>
<script>
const data = {"name": "Alice", "age": 30};
document.getElementById('json-display').textContent =
JSON.stringify(data, null, 2);
</script> JSON.stringify(data, null, 2) formats the JSON with 2-space indentation. The <pre> tag preserves whitespace. Add a CSS class for syntax highlighting using Prism.js.
Method 3: JSON as an HTML Table with JavaScript
If you are building a webpage dynamically:
function jsonToTable(data) {
if (!data.length) return '<p>No data</p>';
const headers = Object.keys(data[0]);
const headerRow = headers.map(h => `<th>${h}</th>`).join('');
const rows = data.map(row =>
'<tr>' + headers.map(h => `<td>${row[h] ?? ''}</td>`).join('') + '</tr>'
).join('');
return `<table><thead><tr>${headerRow}</tr></thead><tbody>${rows}</tbody></table>`;
} Call it with: document.body.innerHTML = jsonToTable(yourJsonArray);
Method 4: JSON Tree View in HTML
For nested/hierarchical JSON, a collapsible tree view is more readable than a table. Use a lightweight library:
- json-viewer (
<json-viewer>web component) — add via CDN, pass JSON as a property. - JSONEditor — open-source library with tree, code, and table views.
- react-json-view — if you are using React.
Which Method to Use?
- Tabular JSON (array of objects): → HTML table (Method 1 or 3)
- Display JSON code on a page: →
<pre><code>block (Method 2) - Nested/complex JSON: → tree view library (Method 4)
Frequently Asked Questions
How do I convert JSON to HTML?
The most common approach is converting JSON data to an HTML table. Use TextWonder's CSV to HTML Table tool: first convert JSON to CSV, then convert the CSV to an HTML table. You get a complete <table> element ready to paste into any webpage.
How do I display JSON data as an HTML table?
Convert the JSON to CSV using the JSON to CSV tool, then paste the CSV into the CSV to HTML Table converter. It generates a properly formatted HTML table with <thead> headers and <tbody> rows.
Can I convert JSON to HTML with JavaScript?
Yes. Use JSON.parse() to parse the JSON, then build HTML strings with template literals or use the DOM API. For a table: iterate over the array, create <tr> and <td> elements for each object and its values.
How do I pretty-print JSON in an HTML page?
Wrap the JSON in a <pre><code> block and use JSON.stringify(data, null, 2) to format it with 2-space indentation. For syntax highlighting, use a library like Prism.js or highlight.js.
What is the best way to render JSON data on a webpage?
For tabular JSON (arrays of objects): render as an HTML table. For hierarchical/nested JSON: render as a collapsible tree using a library like json-viewer. For raw display: use <pre><code> with JSON.stringify formatting.