Markdown vs JSON for AI

When to use each format for prompts, context, and output

Two Formats, Different Jobs

Markdown is for humans. It structures text with headings, lists, and code blocks while remaining readable as raw text. AI tools use it for documentation, instructions, and narrative output.

JSON is for machines. It structures data with strict syntax — keys, values, arrays, and nested objects. AI tools use it for API responses, function calls, and data extraction.

Both are essential in AI workflows. The question is when to use which.

Quick Comparison

Markdown JSON
Primary audience Humans Machines (code)
Token efficiency Better for text-heavy content Better for flat data
Parsing Flexible (tolerates errors) Strict (one missing comma = invalid)
Structure Headings, lists, tables Keys, values, arrays, objects
AI training data Abundant (GitHub, docs) Abundant (APIs, configs)
Error recovery Graceful (renders what it can) Binary (valid or invalid)
Version control Clean diffs Noisy diffs (commas, brackets)

Use Markdown For

  • System prompts — instructions for the AI (“You are a helpful assistant that...”)
  • Context filesCLAUDE.md, AGENTS.md, README.md
  • Documentation output — READMEs, guides, changelogs, reports
  • Explanations — code reviews, debugging analysis, architecture discussions
  • Mixed content — text with embedded code blocks, tables, and diagrams
  • Human-facing chat — conversational AI responses

Use JSON For

  • API responses — structured data that code will parse
  • Function/tool calling — arguments for AI function calls
  • Data extraction — pulling structured fields from unstructured text
  • Classification — categorizing items into predefined labels
  • Configuration — settings, parameters, options
  • Machine-to-machine — AI output consumed by another program

Token Cost Comparison

For the same information — a list of three items with descriptions:

Markdown (~30 tokens) ## Items - **Widget** — A small component - **Gadget** — A larger device - **Doohickey** — An unknown thing
JSON (~45 tokens) { "items": [ {"name": "Widget", "description": "A small component"}, {"name": "Gadget", "description": "A larger device"}, {"name": "Doohickey", "description": "An unknown thing"} ] }

Markdown is ~30% more token-efficient for descriptive content. JSON’s overhead comes from quotes, commas, colons, and brackets.

For pure data (a list of numbers, a simple key-value map), the difference is smaller. But for anything with narrative text, Markdown wins on tokens.

The Hybrid Pattern

Most production AI workflows use both formats:

  • System prompt → Markdown (instructions, context, examples)
  • User input → JSON or Markdown (depends on the data)
  • AI output → JSON for structured data, Markdown for explanations

For example, a code review agent might receive Markdown context (CLAUDE.md) and a JSON diff, then output a JSON array of findings with Markdown descriptions inside each finding.

When Format Doesn’t Matter

For interactive chat with humans, the format choice is already made — every major AI chat interface renders Markdown. ChatGPT, Claude, Gemini — they all output Markdown and their web UIs render it.

The format question only matters when you’re building AI into a product or workflow, and you need to decide how the AI communicates with your code.

Related Guides

View AI Markdown with MDViewer

MDViewer renders Markdown output from any AI tool — syntax highlighting, tables, Mermaid diagrams, and math. Native macOS app.

Download MDViewer

Requires macOS 13.0 or later. Intel and Apple Silicon.