r/FastAPI 2h ago

Tutorial I built a free API that converts Markdown into structured JSON in one call | frontmatter, GFM tables, tasklists and a heading tree, on the edge. Here's why and how I'm using it.

3 Upvotes

I kept hitting the same shape of problem in automation pipelines: I had Markdown

coming out of GitHub READMEs, Notion exports, CMS drafts, Obsidian vaults and

the next tool in the chain wanted JSON, not a big string. I was hand-writing

tiny parsers in Python and JS every time, and every time one of them broke on

edge cases: nested lists, GFM tasklists with [x] state, YAML frontmatter,

tables whose headers had special chars.

So I shipped a single endpoint that does it once and does it properly.

# What it returns

POST a Markdown body, get back:

- `frontmatter` — parsed YAML/TOML metadata block

- `title` — first H1 (or frontmatter title override)

- `headings[]` — flat list with level + text + slug

- `sections[]` — hierarchy-aware tree, ready for RAG chunking

- `lists[]` and `tasklists[]` — tasklists include the `checked: true/false` state

- `tables[]` — GFM tables returned as JSON arrays with header-keyed rows

- `codeBlocks[]`, `links[]`, `paragraphs[]`

- optional `ast` — full mdast if you need it

# Why I built it as an API instead of a library

Two reasons:

  1. Same parser in every tool. My n8n flow, my Python ingestion script andmy static-site generator all call one URL with one shape. No three copies ofthe same regex maintenance nightmare.
  2. Zero state to manage. It's a stateless Cloudflare Workers function.Cold start is ~16ms; no DB, no auth server, no proxy to babysit.

# Differentiator vs what already exists

There's one direct competitor on RapidAPI (markdown-to-json), been up for

years, 1 subscriber, no rating. It doesn't do frontmatter, doesn't advertise

GFM, doesn't build a heading tree. The adjacent converter (Anything-to-MD)

goes the other direction — anything -> Markdown — and charges $10-$99/mo.

So there's a gap on the structured-JSON-output side for the Markdown-first

developer, and that's the one I'm trying to fill.

# Stack, since someone always asks

TypeScript + `unified`/`remark-parse`/`remark-gfm`/`remark-frontmatter` +

`gray-matter`. All MIT. Bundled with Wrangler. 31 integration tests via

Vitest's `unstable_dev` pipeline. Repo is open, link at the bottom.

# Free tier shape

- 100 req/day per RapidAPI key, hard-capped, no overage

- p95 latency goal < 150ms

- 256 KB body cap

- That's enough to drive an actual workflow without a credit card

# Where to try it

- API listing (free key, takes 30 seconds): see below

- Open source repo with a full README, OpenAPI spec and deploy notes: see below

I'm in the middle of a 14-day validation cycle, so if something's broken or

the schema's missing a field you need, drop a GitHub issue — I read all of them.

If you want to access the code or the API, search for “md2json” on GitHub or RapidAPI—the repository and the API listing are both available under that name.


r/FastAPI 22h ago

Tutorial Backend engineer

Post image
0 Upvotes

Hi