See how we built our intranet. Live + Q&A, June 30 →

NextJS getServerSideProps serialization error with undefined values from Sanity

3 repliesLast updated: Nov 29, 2025

Hi there 🙂 Any tips for what causes this error message?I’m using NextJS and Sanity.

Server Error
Error: Error serializing
.artists
returned from
getServerSideProps
in “/exhibitions/[slug]“.Reason:
undefined
cannot be serialized as JSON. Please use
null
or omit this value.
AI Update

This error happens because Next.js can't serialize undefined values when passing props from getServerSideProps to your component. Next.js uses JSON to transfer data from server to client, and undefined isn't valid JSON.

In your case, the .artists field is coming back as undefined from your Sanity query, likely because:

How to fix it:

Option 1 - Use nullish coalescing in your return statement:

return {
  props: {
    ...exhibition,
    artists: exhibition.artists || null
  }
}

Option 2 - Spread the entire query response (cleaner approach):

return {
  props: { ...exhibition }
}

Option 3 - Filter out undefined values:

const cleanProps = Object.fromEntries(
  Object.entries(exhibition).filter(([_, v]) => v !== undefined)
);

return {
  props: cleanProps
}

Also check your GROQ query - Make sure there are no syntax errors. Common issues include:

If you share your full query, I can help spot any syntax issues. The GROQ documentation is also helpful for validating query syntax.

Show original thread
3 replies

Was this answer helpful?

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.

Related contributions