✍️ TextWonder 📄 PDFWonder 📁 DocWonder 🖼️ ImageWonder 🛠️ DevWonder 🎓 StudentWonder 🧮 CalcWonder 🩺 HealthWonder 🎨 ColorWonder 💾 DataWonder 📐 UnitWonder
TextWonder
Data Converters · 5 min read ·

How to Convert JSON to HTML — Table, Tree & Code Display

Convert JSON to HTML online for free. Turn JSON arrays into HTML tables, display JSON as formatted code blocks, or render as a tree. Step-by-step guide with examples.

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

  1. Convert the JSON to CSV first using the JSON to CSV tool.
  2. Copy the CSV output.
  3. Open the CSV to HTML Table converter.
  4. Paste the CSV data and click Convert.
  5. Copy the generated HTML table code — it includes <thead> with headers and <tbody> rows.
  6. Paste into your HTML file.
Free Tool
CSV to HTML Table Converter →
Paste CSV data and get a fully formatted HTML table with headers and rows. Copy the code and paste it into any webpage. Free, browser-based.

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:

Which Method to Use?

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.