Back to blog
6 min read Export Guides

Export WordPress Posts to JSON for a Headless Front End (Astro, Next.js)

A headless front end built with Astro, Next.js or another static site generator needs your WordPress posts as data. The usual route is the WordPress REST API or WPGraphQL, which means the WordPress site has to be online and reachable every time the front end builds. For a blog that changes a few times a month, a JSON file is simpler: export the posts once, commit the file to the front end’s repository, and build from it. With Import Export by RockStarLab, you choose the posts and fields and name the JSON keys the way your front end expects. The example is a small Astro blog built from a coffee roastery’s journal.

Free: JSON export of posts and pages with your own key names. PRO: the same for custom post types and WooCommerce products.

Short Answer

  1. In Export, choose Posts and filter to the posts the front end should show, for example one category and Status publish.
  2. Add Slug, Title, Date, Excerpt, Content, Featured Image URL, Featured Image Alt and Category Names, and rename each with the pencil icon to the key your front end uses.
  3. Choose JSON, download the file and load it in the front end: in Astro with the file() loader of a content collection.

Choose the posts

Our front end shows the roastery’s Journal category. A Taxonomy Filter on category with the condition Has Term(s) – IN selects those posts:

Export filter: Taxonomy Filter, taxonomy category, condition Has Term(s) - IN, term journal-headless; total items available 4
Only the posts in the Journal category go to the front end.

If the category could contain drafts, add a Status filter Equals publish; the export includes every status otherwise.

Name the JSON keys

Each column becomes a key in every JSON object. Rename the columns to short, code-friendly names:

Export File Structure with eight columns renamed: slug (post_name), title (post_title), date (post_date), excerpt (post_excerpt), content (post_content), image (featured_image_url), imageAlt (featured_image_alt), categories (category_names)
The column names become the JSON keys your front end reads.
  • Slug (post_name) → slug: the URL of each page on the front end.
  • Title → title, Date → date, Excerpt → excerpt.
  • Content → content: the post’s HTML, ready to render.
  • Featured Image URL → image and Featured Image Alt → imageAlt.
  • Category Names → categories.

Use names without spaces or dashes, so they work as property names in JavaScript.

Export as JSON

On the next step, choose JSON. Pretty Print is on by default and keeps the file readable in code review. Name the file posts and start the export.

Export Completed Successfully screen with Items Exported, File Size and Duration and a Download Export File button
Download posts.json and put it in the front end's project.

The file is an array with one object per post:

[
    {
        "slug": "how-we-source-green-coffee",
        "title": "How We Source Green Coffee",
        "date": "2026-10-14 09:00:00",
        "excerpt": "Direct trade, fair prices and long relationships.",
        "content": "<!-- wp:paragraph -->\n<p>Intro paragraph for how we source green coffee.</p>\n<!-- /wp:paragraph -->\n\n…",
        "image": "https://www.example-roastery.com/wp-content/uploads/2026/11/farm-visit.jpg",
        "imageAlt": "",
        "categories": "Journal"
    },
    …
]

Things to know about the values:

  • content is the HTML stored in WordPress, including the block comments such as <!-- wp:paragraph -->. Browsers ignore them, so you can render the HTML as it is.
  • Images inside the content and in image still point to your WordPress uploads folder. Keep the WordPress site online for the images, or copy the uploads to the front end and replace the domain.
  • date is in WordPress’s format and your site’s time zone.
  • imageAlt is empty when the image has no alt text in the Media Library; give your template a fallback.

Build an Astro blog from the file

We put the file in src/data/posts.json of a new Astro 5 project. A content collection loads it with the file() loader and uses the slug as each entry’s ID:

import { defineCollection, z } from 'astro:content';
import { file } from 'astro/loaders';

const posts = defineCollection({
  // posts.json is the file exported from WordPress
  loader: file('src/data/posts.json', {
    parser: (text) => JSON.parse(text).map((post) => ({ id: post.slug, ...post })),
  }),
  schema: z.object({
    slug: z.string(),
    title: z.string(),
    date: z.coerce.date(),
    excerpt: z.string(),
    content: z.string(),
    image: z.string(),
    imageAlt: z.string(),
    categories: z.string(),
  }),
});

export const collections = { posts };

A dynamic route creates one page per post, src/pages/blog/[slug].astro:

---
import { getCollection } from 'astro:content';
export async function getStaticPaths() {
  const posts = await getCollection('posts');
  return posts.map((post) => ({ params: { slug: post.id }, props: { post } }));
}
const { post } = Astro.props;
---
<article>
  <h1>{post.data.title}</h1>
  <time datetime={post.data.date.toISOString()}>{post.data.date.toDateString()}</time>
  {post.data.image && <img src={post.data.image} alt={post.data.imageAlt || post.data.title} />}
  <Fragment set:html={post.data.content} />
</article>

Together with a simple list page, the build produced a page for each of the four posts, named after their WordPress slugs:

$ npm run build
 generating static routes
▶ src/pages/blog/[slug].astro
  ├─ /blog/how-we-source-green-coffee/index.html
  ├─ /blog/five-single-origin-coffees-to-try-this-winter/index.html
  ├─ /blog/meet-the-team-behind-the-beans/index.html
  └─ /blog/our-new-roastery-opens-in-march/index.html
▶ src/pages/blog/index.astro
  └─ /blog/index.html
[build] 5 page(s) built in 638ms

In Next.js, import the same file in your page and return the slugs from generateStaticParams. Any tool that reads JSON can use it the same way.

Keeping the front end up to date

When you publish or edit posts, run the same export again and replace the file. To export only what changed since the last run, see incremental exports. If the site changes several times a day, the REST API is the better source; a JSON file suits a front end that is rebuilt on purpose.

Before you switch

An export only reads your content. If you clean up slugs, excerpts or alt text before the export, for example by import, back up the site first.

With an AI agent

An AI agent connected through the WordPress MCP Adapter (see connecting Claude Code to WordPress) can refresh the file for you, for example from the front end’s repository in Claude Code:

Export the published posts in Journal to posts.json with the keys slug, title, date, excerpt, content, image, imageAlt and categories.

In our run, the agent called rsl-ie/export-start with the format json, the category, the Status filter and the eight fields renamed through column_headers. When the job finished, rsl-ie/file-get returned posts.json, 5,224 bytes, the same size as the file from the wizard.

FAQ

Why not use the REST API?

You can. A JSON file is useful when the front end should build without a connection to WordPress, or when you want the content in the repository with its history.

Can I export pages for the front end too?

Yes. Run the same export with Pages; add Parent Title or the parent’s slug if your front end builds nested URLs.

Can I include custom fields or ACF fields?

Yes. Add them from Custom Fields or ACF Fields in the field list and rename them like the other columns.

Is the content HTML or Markdown?

HTML, as WordPress stores it. Render it with set:html in Astro or dangerouslySetInnerHTML in React, or convert it to Markdown in your build if you prefer.

Get the free plugin on WordPress.org.

Dmitriy
About author

Dmitriy

WordPress Developer with 15+ years of commercial experience. Elite Author on ThemeForest and creator of custom WordPress plugins. Passionate about clean code, performance optimization, and building useful tools for the WordPress community.

JOIN THE CONVERSATION

Comments 0

Have a question or a tip to share? Leave it below.

Leave a comment

Your email address will not be published. Required fields are marked *

We store your name, email and comment to show and moderate it; your email is never published. Spam protection is provided by Cloudflare Turnstile and profile pictures by Gravatar. See our Privacy Policy.


Try the plugin with no risks!

New users get 1 month with access to all premium features. Experience the most powerful WordPress data engine today.

Download Now
Get PRO for FREE