{"id":705,"hash":"71e873e1e39def2ee3ab494ce1881ef73b09ef3dc018e38aad665b4ba80c1423","pattern":"Reason: `object` (&quot;[object Date]&quot;) cannot be serialized as JSON. Please only return JSON serializable data types","full_message":"I am using Prisma and Next.js. When I try to retrieve the content from Prisma in getStaticProps it does fetch the data but I can't pass it on to the main component.\n\nexport const getStaticProps = async () => {\n  const prisma = new PrismaClient();\n  const newsLetters = await prisma.newsLetters.findMany();\n  console.log(newsLetters);\n\n  return {\n    props: {\n      newsLetters: newsLetters,\n    },\n  };\n};\n\nAs you can see in this image it is fetching as well as printing the content.\n\nBut when I pass I get the following error for passing it as props\n\nReason: `object` (\"[object Date]\") cannot be serialized as JSON. Please only return JSON serializable data types.","ecosystem":"npm","package_name":"next.js","package_version":null,"solution":"Looks like nextJS doesn't like serializing anything but scalar types for performance reasons. You can read more in this github issue. Best way you can handle this is that you convert your Date objects to UNIX timestamp before returning them.\n\n// your data\nlet newsLetters = [\n    {\n        id: 'your-id',\n        email: 'email@example.com',\n        createdAt: new Date()\n    }\n];\n\n// map the array\nnewsLetters.map(x => {\n    x.createdAt = Math.floor(x.createdAt / 1000);\n    return x;\n})\n\n// use newsLetters now\nconsole.log(newsLetters);","confidence":0.9,"source":"stackoverflow","source_url":"https://stackoverflow.com/questions/70449092/reason-object-object-date-cannot-be-serialized-as-json-please-only-ret","votes":27,"created_at":"2026-04-19T04:51:32.033138+00:00","updated_at":"2026-04-19T04:51:32.033138+00:00"}