🛠️ToolsShed

JSON toテーブル

JSON配列をHTMLまたはMarkdownテーブルで視覚化します。

よくある質問

コード実装

def json_to_markdown_table(data: list[dict]) -> str:
    if not data:
        return ""
    headers = list(data[0].keys())
    rows = []
    rows.append("| " + " | ".join(headers) + " |")
    rows.append("| " + " | ".join(["---"] * len(headers)) + " |")
    for row in data:
        cells = [str(row.get(h, "")) for h in headers]
        rows.append("| " + " | ".join(cells) + " |")
    return "\n".join(rows)

data = [
    {"name": "Alice", "age": 30, "city": "Seoul"},
    {"name": "Bob",   "age": 25, "city": "Tokyo"},
]
print(json_to_markdown_table(data))

Comments & Feedback

Comments are powered by Giscus. Sign in with GitHub to leave a comment.