Prompt to extract CMS collection items from live pages into JSON
This prompt asks an AI assistant to read the live pages of one CMS collection, such as a blog, pull out each field named in a schema, write validated items.json, and report items with missing fields. Only after you approve it does it load the records into MDX files, a JSON file or a database.
Last reviewed
Key facts
- The schema comes first. It names each field, its type and whether it is required, so a missing value is reported, not guessed.
- Pages with JSON-LD or Open Graph tags give clean values for title, date, author and image. Body content needs selectors for your own markup.
- Firecrawl can extract fields from a page into JSON when you pass a schema, at an extra credit cost per page.
- Test status: the reference script was run on two real pages of webexport.online (a blog post and a guide) and produced 2 items with slug, title, description, dates, author, image and a Markdown body, none with missing required fields. Collection pages from a Webflow, Framer, Squarespace, Shopify or Wix site were not tested, loading into MDX or a database was not run, and the Firecrawl JSON format was not run.
The prompt
Paste this into Claude Code, Cursor, Codex or another AI coding assistant with your project folder open, and replace everything in square brackets first. See how to run it in each tool.
You are turning the pages of one CMS collection into structured data. The collection lives at [COLLECTION_URL, for example https://example.com/blog]. Each item has its own page.
READ
- The collection index at [COLLECTION_URL] and every item page it links to, up to [MAX_ITEMS: 100] items.
- If the site was exported with WebExport, the matching .html files in [EXPORT_FOLDER] may be used instead of the live pages.
STEP 1: SCHEMA
Write schema.json, a JSON Schema for one item. Use these fields: [FIELDS: slug, title, description, date, author, image, body]. Mark [REQUIRED_FIELDS: slug, title, body] as required.
STEP 2: EXTRACT
For each item page, fill the schema. Prefer values from JSON-LD, then Open Graph tags, then the page markup. Convert the body to Markdown and keep headings, lists, links and image alt text. Write all items to items.json and add a "missing" list to each item.
STEP 3: REPORT
Write EXTRACT.md with the item count, every item with a missing required field, every duplicate slug, and any field where the values look wrong (a date in the future, an empty body).
STEP 4: LOAD, ONLY AFTER I APPROVE
Write the items to [TARGET: MDX files in content/blog, a single JSON file, or a SQLite table]. For MDX, put every field except body in frontmatter.
RULES
- Do not invent a value. Leave a field empty and list it as missing.
- Do not change or delete the source pages.
- Use GET requests only, at most 5 at a time, and never submit a form.
- If scripts/extract-items.mjs exists, start from it and change only the selector lines.How to run it
- Open one item page in a browser and note where each field appears: title, date, author, image and body.
- Send the prompt with the collection URL, the field list and the target format. Stop after step 3.
- Read EXTRACT.md and spot-check five items against the live pages.
- Tell the assistant to run step 4, then build the site and open a few items.
Run it without a paid key
The script reads a text file of URLs, one per line, and writes items.json to the standard output. It looks for an Article or BlogPosting node in JSON-LD first, then Open Graph and meta tags, then the first h1, and it builds the body from the article or main element. The block marked SELECTORS is the part to change for markup of your own.
// Usage: node extract-items.mjs urls.txt > items.json
// Pulls one record per URL using JSON-LD, Open Graph and <article> markup. Adapt the SELECTORS section for your own pages.
import fs from 'node:fs';
const urls = fs.readFileSync(process.argv[2], 'utf8').split('\n').map((l) => l.trim()).filter(Boolean);
const decode = (s = '') => s.replace(/&/g, '&').replace(/"/g, '"').replace(/'|'/g, "'").replace(/</g, '<').replace(/>/g, '>');
const meta = (h, p) => decode(h.match(new RegExp(`<meta[^>]+(?:property|name)=["']${p}["'][^>]*content=["']([^"']*)`, 'i'))?.[1]);
const REQUIRED = ['title', 'slug', 'body'];
function jsonLd(h) {
for (const m of h.matchAll(/<script[^>]+application\/ld\+json[^>]*>([\s\S]*?)<\/script>/gi)) {
try {
const j = JSON.parse(m[1]);
const nodes = j['@graph'] ?? [j];
const hit = nodes.find((n) => /Article|BlogPosting/.test(String(n['@type'])));
if (hit) return hit;
} catch { /* ignore broken JSON-LD */ }
}
return {};
}
function toMarkdown(html) {
const region = html.match(/<article[\s\S]*?<\/article>/i)?.[0] ?? html.match(/<main[\s\S]*?<\/main>/i)?.[0] ?? '';
return decode(region
.replace(/<(script|style|nav|footer|aside|svg|form|button)[\s\S]*?<\/\1>/gi, '')
.replace(/<h([1-6])[^>]*>([\s\S]*?)<\/h\1>/gi, (_, n, t) => `\n\n${'#'.repeat(Number(n))} ${t.replace(/<[^>]+>/g, '').trim()}\n\n`)
.replace(/<li[^>]*>([\s\S]*?)<\/li>/gi, (_, t) => `\n- ${t.replace(/<[^>]+>/g, '').trim()}`)
.replace(/<\/p>/gi, '\n\n').replace(/<[^>]+>/g, '').replace(/[ \t]+/g, ' ').replace(/\n{3,}/g, '\n\n').trim());
}
const items = [];
for (const url of urls) {
const r = await fetch(url, { signal: AbortSignal.timeout(15000), headers: { 'user-agent': 'extract-items/1.0' } });
const h = await r.text();
const ld = jsonLd(h);
// SELECTORS: change these lines to match your own markup
const item = {
slug: new URL(url).pathname.split('/').filter(Boolean).pop(),
title: decode(ld.headline) || meta(h, 'og:title') || decode(h.match(/<h1[^>]*>([\s\S]*?)<\/h1>/i)?.[1]?.replace(/<[^>]+>/g, '').trim()),
description: decode(ld.description) || meta(h, 'description'),
date: ld.datePublished || h.match(/<time[^>]+datetime=["']([^"']+)/i)?.[1] || '',
updated: ld.dateModified || '',
author: ld.author?.name || '',
image: meta(h, 'og:image') || '',
body: toMarkdown(h),
source_url: url,
};
item.missing = REQUIRED.filter((k) => !item[k]);
items.push(item);
}
console.log(JSON.stringify(items, null, 2));
console.error(`${items.length} items, ${items.filter((i) => i.missing.length).length} with missing required fields`);node scripts/extract-items.mjs urls.txt > items.jsonThe Firecrawl path
The scrape endpoint accepts a json format with a schema and an optional prompt, so Firecrawl fills the fields for you from the rendered page. The billing page lists the JSON format as 4 extra credits per page, so a 100-item collection costs more than a plain scrape of the same pages. The older extract endpoint is described in the docs as replaced by the agent endpoint, so this page does not use it.
curl -s -X POST https://api.firecrawl.dev/v2/scrape \
-H "Authorization: Bearer $FIRECRAWL_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"url": "https://example.com/blog/first-post",
"formats": [
{
"type": "json",
"schema": {
"type": "object",
"properties": {
"title": { "type": "string" },
"date": { "type": "string" },
"author": { "type": "string" }
},
"required": ["title"]
}
}
]
}'Verify the result
Count the items against the collection, then compare a few records with the live pages.
node -e "const a=require('./items.json');console.log(a.length+' items,',a.filter(i=>i.missing.length).length+' with missing fields')"
node -e "const a=require('./items.json');const s=a.map(i=>i.slug);console.log(s.length-new Set(s).size+' duplicate slugs')"
ls content/blog | wc -l- The item count equals the number of entries listed on the collection index.
- Five records picked at random match their live pages for title, date and the first paragraph.
- No required field is empty in the loaded output, and links and images still point to real files.
What can go wrong
- Dates in a different time zone or format can shift by a day. Compare against the live page.
- Rich text embeds, such as a video or a form, do not turn into Markdown. The report should list pages that contain them.
- A list page with pagination or a load-more button hides items from a plain fetch. Check the count against what you see in the browser.
Frequently asked questions
Why write a schema before extracting?
A schema tells the assistant what counts as a field and what is required, so a missing value is reported instead of invented. It also lets you validate every record.
Is this the same as the CMS to MDX prompt?
It starts earlier. This prompt works from live pages and produces JSON. The CMS to MDX prompt works from exported HTML files.
Can I get the data without scraping?
Check whether your platform has its own CMS export first. For Webflow, the Webflow CMS Export to CSV tool converts collection JSON you paste into a CSV. Use scraping when you have no such access.
Where do images go?
The script keeps the image URL. Download the files into the project and rewrite the URLs so the new site does not depend on the old platform's CDN.
Official documentation
Free tools for this job
- Webflow CMS Export to CSVPaste Webflow CMS collection JSON and convert it to a downloadable CSV.
- Markdown ConverterConvert files, pasted text, webpage content, Notion, and Google Docs into Markdown.
- Website MD File GeneratorConvert any webpage into a clean Markdown file optimized for AI ingestion.
- No-Code Asset Path NormalizerRewrite CDN URLs to local relative paths for offline and self-hosted deployments.
Start with the files
Prompts work best on a WebExport download of your site. Paste your public URL into the export form and get a ZIP. The Free plan covers 1 site, 5 exports a month, 15 pages and 20 MB per export. Professional is a $9.99 one-time purchase with unlimited pages.