
Grab your gear: The official Sanity swag store
Read Grab your gear: The official Sanity swag storeGreat to hear you're loving Sanity! Yes, you can absolutely convert Portable Text to plain text strings, similar to Prismic's $prismic.asText(). There are several ways to do this:
pt::text() in GROQ queries (Recommended)The most efficient approach is using the built-in pt::text() GROQ function directly in your queries:
*[_type == "post"] {
title,
"description": pt::text(body)
}This converts your Portable Text field to plain text at query time, which is perfect for generating excerpts, meta descriptions, or search indexing.
For client-side conversion, you have a few npm package options:
toPlainText functionExample usage:
import {toPlainText} from '@portabletext/toolkit'
const plainText = toPlainText(portableTextBlocks)If you want a lightweight solution without dependencies, here's a simple function from the Sanity docs:
function toPlainText(blocks = []) {
return blocks
.map(block => {
if (block._type !== 'block' || !block.children) {
return ''
}
return block.children.map(child => child.text).join('')
})
.join('\n\n')
}This traverses the Portable Text block structure and extracts just the text content, joining paragraphs with double line breaks.
pt::text() in GROQ if you're querying data and want plain text in your API response@portabletext/toolkit if you need to convert Portable Text on the client sideAll of these will give you functionality equivalent to Prismic's asText() method!
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.
Content operations
Content backend


The only platform powering content operations
By Industry


Tecovas strengthens their customer connections
Build and Share

Grab your gear: The official Sanity swag store
Read Grab your gear: The official Sanity swag store