Glossary

JSON vs Markdown for LLMs

Markdown is usually the better format for giving a language model documents to read, while JSON is better for structured records and for outputs that code will parse and validate.

JSON and Markdown are the two formats most often used to pass content into a large language model and to get structured content back out. Markdown is usually the better format for giving a model documents to read: it is compact, close to the prose models were trained on, and keeps headings, lists and tables in a form the model follows easily. JSON is usually the better format for data that code will consume: records with named fields, values that must be validated, and outputs that another system will parse. The common pattern is Markdown in for context and JSON out for results, with JSON also used for inputs that are naturally tabular or keyed records. The choice affects token count, accuracy and how easily the output can be checked.

Why the format matters

A language model reads everything as a sequence of tokens, so the same content costs a different number of tokens and is understood differently depending on its format. Tokenization of JSON spends tokens on braces, quotation marks, repeated key names and escaped characters, while Markdown spends them mostly on the words themselves. In a fixed context window, overhead from formatting is space that could have held more source material, and it adds to the per-request bill, as input vs output tokens explains.

Format also shapes how well the model follows structure. Models have seen enormous amounts of Markdown in documentation, READMEs and web pages, so a heading hierarchy or a numbered list in Markdown is read in the way a person would read it. Long JSON objects, especially deeply nested ones, are easier for a model to lose track of: which field belongs to which object, where one record ends and the next begins.

On the output side the priorities reverse. Code cannot reliably parse free-form prose or loosely formatted Markdown, but it can parse JSON, validate it against a JSON schema and reject it if a required field is missing.

Markdown for LLM input

Markdown is a light syntax for structured text: # for headings, - or numbers for lists, pipes for tables, and fenced blocks for code. Converting a PDF, web page or slide deck to Markdown keeps the structure that matters for understanding (section titles, list items, table rows, emphasis) while dropping layout details the model does not need. This is why so many extraction and scraping tools now offer Markdown output, and why HTML to Markdown conversion is a standard step when preparing web content as LLM-ready data.

Markdown has limits. Its tables struggle with merged cells, multi-line cells and nested structure, and wide tables become hard to read as plain pipes. It has no types: a number, a date and a string all look the same. And there is no schema, so nothing guarantees that a field is present or named consistently across documents.

JSON for LLM input and output

JSON represents data as objects with named keys, arrays and typed values. As input it suits content that is already a set of records: a list of products with prices, a user profile, the results of an API call, rows from a database. Key names act as labels that tell the model what each value means, and the model can reason about specific fields without guessing.

As output JSON is the default for anything a program will use. Most model providers support structured output or a JSON mode, and many use constrained decoding to guarantee the response matches a supplied schema. Function calling also returns its arguments as JSON. The difference between those two mechanisms is covered in function calling vs structured output.

The costs are verbosity and, for long documents, readability. A 10-page report wrapped as JSON, with every paragraph as a string value full of escaped quotation marks and newline characters, costs more tokens than the same report in Markdown and is harder for the model to follow.

Side by side

Markdown

JSON

Best use

Documents and prose given to the model

Records, parameters and outputs for code

Token overhead

Low

Higher, from keys, quotes and brackets

Structure

Headings, lists, simple tables

Nested objects, arrays, typed values

Validation

None

Schema validation possible

Model familiarity

Very high, common in training data

High, but long nesting is harder to follow

Tables

Good for simple tables

Good for any shape, more verbose

Parsing by code

Unreliable beyond simple cases

Standard and strict

Typical role in RAG

Retrieved context

Extracted fields, tool calls, final answers

A worked example

Consider an invoice processed in two ways and passed to a model that must answer “Is anything on this invoice overdue?” and then return the result to an accounts system.

As JSON input, the invoice might look like {"vendor": "Northwind Supplies", "invoiceNumber": "INV-20419", "dueDate": "2026-11-03", "lineItems": [...], "total": 4812.50}. The model can read the due date directly, and every field is labelled. For one invoice that is ideal; for a 30-page supplier agreement it would not be.

As Markdown input, the same invoice reads as a heading with the vendor name, a short list of invoice number and dates, and a table of line items with columns for description, quantity and amount. The prose of the payment terms (“Late payments incur interest at 2% per month after 30 days”) sits underneath as ordinary text, which matters because the overdue question depends on it. The Markdown version uses noticeably fewer tokens than a JSON version that includes the full terms as string values, and the model handles the terms paragraph naturally.

For the output, the accounts system needs {"overdue": true, "daysOverdue": 26, "amountDue": 4812.50}, so the request uses structured output with a schema. Markdown went in because the model had to read; JSON came out because code had to act.

Practical guidance

Use Markdown for retrieved passages, documents and long instructions. Keep headings, because they help the model understand where a passage sits in its source, and keep tables simple. When a passage was retrieved from a larger document, prefix it with a short source line (title, page) rather than wrapping it in a JSON envelope.

Use JSON for records, tool results and anything with many small labelled values. Keep nesting shallow and key names short but meaningful, and avoid sending fields the model does not need. For repeated records with the same keys, a compact Markdown table or a CSV-style block can be cheaper than an array of objects, at the cost of losing types.

For outputs, use structured output with a schema wherever the result will be parsed, and validate it anyway. Ask for Markdown only when the output is for a person to read.

Mixed prompts are normal. A typical system prompt uses Markdown headings to separate instructions, examples and context, includes retrieved passages as Markdown, and embeds a small JSON block for user profile data. Choosing the format per section, rather than for the whole prompt, is part of context engineering.

Test on your own data. Format effects vary by model and task, and a small evaluation comparing two formats on real queries is more useful than general advice, including this page.

Other formats and edge cases

JSON and Markdown are not the only options. Many prompts use XML-style tags, such as a pair of document tags around each retrieved source, to mark where one piece of context ends and the next begins. Tags are cheap in tokens, make boundaries unambiguous even when the content itself contains Markdown, and are easy to reference in instructions (“answer only from the documents above”). They combine well with Markdown inside each tag.

CSV or a plain delimited block is often the cheapest way to send a long list of uniform records, since column names appear once instead of on every row. The trade is that values containing commas or line breaks need quoting, and the model has to keep track of column positions across long rows, which gets harder as tables widen.

Plain text with no markup at all is fine for short passages, but loses the headings and list structure that help a model place a passage in its source. Code belongs in fenced code blocks, whatever the surrounding format, so the model does not confuse code with instructions.

Two edge cases deserve care. JSON values that contain Markdown, such as a description field holding a formatted paragraph, double the escaping and are easy for a model to mangle when it writes them back. And any format that carries text from outside sources can carry instructions too, so retrieved content should be clearly delimited and treated as data rather than commands.

Where Exabase fits

Exabase Extract returns both formats from the same job. By default a completed extraction is structured JSON: metadata, text chunks with page numbers or timestamps, and, for invoices, resumes and contracts, a structured object with typed fields such as vendor, line items and total. Adding ?format=markdown when fetching the result returns the same content as a readable Markdown document, with structured data laid out as labelled sections, ready to place in a prompt. Webhooks can deliver either format through the webhookFormat setting. The retrieving results guide shows both. The same choice is available in the free tools: PDF to Markdown, website to Markdown and invoice to JSON, among others.

Notes stored as Resources through the notepads endpoint are Markdown, which suits agents that write summaries and reports for later retrieval. Sending models compact, relevant context rather than whole documents is also the main lever on token spend, which the reduce token costs solution covers, and the file extraction solution shows the end-to-end pipeline.

Frequently asked questions

Is JSON or Markdown better for LLMs?

It depends on the direction. Markdown is usually better for giving a model documents to read, because it is compact and close to natural text. JSON is better for records and for outputs that code will parse and validate.

Does Markdown use fewer tokens than JSON?

For document content, generally yes. JSON adds tokens for braces, quotation marks, key names and escaped characters. For small sets of labelled values the difference is minor, and JSON’s labels can be worth the cost.

Should I ask an LLM to return JSON or Markdown?

Return JSON when a program will use the result, ideally with structured output and a schema. Return Markdown when a person will read the result, such as a summary or report.

How should I format tables for an LLM?

Simple tables work well as Markdown. Tables with merged cells, nested data or many columns are often clearer as JSON records or as one Markdown table per logical group. Repeating headers for long tables split across chunks helps retrieval.

Is YAML a good alternative?

YAML is less verbose than JSON and often reads well to models, but it is whitespace-sensitive and easier to break when generated. It can work for inputs; for outputs, JSON with a schema is more reliable.

Can Exabase return Markdown instead of JSON?

Yes. Extract results are JSON by default and available as Markdown by adding format=markdown, and extraction webhooks can be set to deliver either format. Invoice, resume and contract fields appear as labelled sections in the Markdown version.

Related pages: JSON, Markdown, structured output, HTML to Markdown, ETL vs ELT, file extraction, best HTML to Markdown API, should every website ship an llms.txt, document extraction use case, Context engineering vs prompt engineering

Cut your token spend and give your agent precise context.

Get started in minutes.

Cut your token spend and give your agent precise context.

Get started in minutes.