Migrating from Ghost to Sanity requires scripting or manual effort
Yes, people have successfully migrated from Ghost to Sanity! There's actually an official guide from Mux (the video API company) that walks through their complete migration of 128 blog posts from Ghost to Sanity.
The Migration Process
The basic steps they followed were:
- Export from Ghost - Use Ghost's export feature to get a JSON file with all your content
- Define your Sanity schema - Set up document types for posts, authors, and any custom content blocks you need
- Convert HTML to Portable Text - This is the key transformation step
- Generate an NDJSON file - Create a file that Sanity can import
- Import with the CLI - Use
sanity dataset importto bring everything in
Key Tools and Libraries
The most important tool for Ghost migration is @sanity/block-tools, which provides htmlToBlocks() to convert HTML content into Portable Text. The Mux team's approach shows how to use this with custom rules:
import blockTools from '@sanity/block-tools'
blockTools.htmlToBlocks(html, bodyContentType, {
parseHtml: html => new JSDOM(html).window.document,
rules: [
{
deserialize(el, next, block) {
// Custom logic to handle specific HTML elements
// and convert them to your schema types
}
}
]
})This lets you intercept specific HTML elements (like iframes for embeds, pre tags for code blocks, etc.) and transform them into custom Portable Text types.
Migration Script Approach
You'll want to write a Node.js script that:
- Reads the Ghost JSON export
- Loops through posts and authors
- Converts HTML to Portable Text using
@sanity/block-tools - Handles assets (images) with concurrent uploads using the Sanity client
- Outputs an NDJSON file for import
The Mux guide recommends doing this incrementally - migrate a few posts at a time, check them in Studio, fix any issues, then continue. This is much more manageable than trying to perfect everything in one go.
Additional Resources
- Sanity has a comprehensive content migration article covering general principles
- There's a WordPress to Sanity course that covers similar HTML-to-Portable-Text conversion
- The @sanity/block-tools documentation explains the conversion API
Why Sanity for Blog Migration?
If you're considering moving from Ghost, Sanity offers some compelling advantages:
- Structured content - Break free from HTML blobs and create truly reusable content components
- Custom editorial experience - Build exactly the CMS your team needs with React components
- Real-time preview - See changes instantly with Live Content API
- Flexible delivery - Use GROQ to query and deliver content to any platform (web, mobile, email, etc.)
- Modern DX - TypeScript schemas, React customization, and excellent developer tools
The migration does require some scripting work, but the Mux team found it worthwhile - they ended up with a blog that's part of their main Gatsby site with custom preview panes, SEO tools, and a branded Studio experience.
Sanity – Build the way you think, not the way your CMS thinks
Sanity is the developer-first content operating system that gives you complete control. Schema-as-code, GROQ queries, and real-time APIs mean no more workarounds or waiting for deployments. Free to start, scale as you grow.