jsondecode.com logo

HomeChevronBlogChevronJSON to Markdown Table: Convert JSON Arrays Instantly

Blog post

JSON to Markdown Table: Convert JSON Arrays Instantly

Convert JSON arrays to Markdown tables with code examples in JavaScript and Python. Use the free online tool or automate in your pipeline.

author

Shashank Jain

Author

14/06/20261 minute 51 seconds read
JSON to Markdown Table: Convert JSON Arrays InstantlyJSON to Markdown Table: Convert JSON Arrays Instantly

Article

Why Convert JSON to Markdown?

Markdown tables are useful for documentation, README files, GitHub wikis, and static site generators. If your data lives in JSON, converting it to Markdown lets you include live data in docs without manually formatting tables.

JavaScript: JSON Array to Markdown Table

function jsonToMarkdownTable(arr) {
  if (!arr.length) return '';
  const headers = Object.keys(arr[0]);
  const divider = headers.map(() => '---').join(' | ');
  const rows = arr.map(row =>
    headers.map(h => String(row[h] ?? '')).join(' | ')
  );
  return [
    headers.join(' | '),
    divider,
    ...rows
  ].join('\n');
}

const data = [
  { name: 'Alice', age: 30, city: 'NYC' },
  { name: 'Bob', age: 25, city: 'London' }
];
console.log(jsonToMarkdownTable(data));
// name | age | city
// --- | --- | ---
// Alice | 30 | NYC
// Bob | 25 | London

Python: JSON to Markdown Table

def json_to_markdown_table(data):
    if not data:
        return ''
    headers = list(data[0].keys())
    rows = [[str(row.get(h, '')) for h in headers] for row in data]
    
    header_row = ' | '.join(headers)
    divider = ' | '.join(['---'] * len(headers))
    body_rows = ['\n'.join(' | '.join(row) for row in rows)]
    
    return f'{header_row}\n{divider}\n' + '\n'.join(' | '.join(row) for row in rows)

import json
with open('data.json') as f:
    data = json.load(f)
print(json_to_markdown_table(data))

Handling Nested Values

function flatten_for_table(arr) {
  return arr.map(row => {
    const flat = {};
    for (const [key, val] of Object.entries(row)) {
      if (typeof val === 'object' && val !== null) {
        flat[key] = JSON.stringify(val); // Serialize nested as JSON string
      } else {
        flat[key] = val;
      }
    }
    return flat;
  });
}

Using tabulate in Python

from tabulate import tabulate
import json

with open('data.json') as f:
    data = json.load(f)

# GitHub Flavored Markdown
print(tabulate(data, headers='keys', tablefmt='github'))

# Pipe format
print(tabulate(data, headers='keys', tablefmt='pipe'))

FAQ

Does jsondecode.com have a JSON to Markdown table tool?

Yes — paste your JSON array into the JSON to Markdown Table converter and get formatted Markdown instantly.

What if my JSON has nested objects?

Nested objects cannot directly become table cells. Either flatten the JSON first (using dot notation for keys) or serialize nested values as JSON strings in the cell.

How do I align columns in a Markdown table?

Use colons in the divider row: :--- for left-align, :---: for center, ---: for right-align.

Can I convert a JSON object (not array) to a Markdown table?

Yes — convert it to a two-column table of key and value: Object.entries(obj).map(([k, v]) => ({ Key: k, Value: v })).

What Markdown table format works best on GitHub?

GitHub supports GitHub Flavored Markdown (GFM) tables. Use the pipe | separator with a divider row of dashes. The tabulate library's github format produces exactly this output.

Keep reading

Recent blogs

View all

If jsondecode.com saved you time, share it with your team

Free forever. No ads. No sign-up. Help other developers find it.