Hi everyone đź‘‹
I’m encountering an issue when making a query in my app. The request fails with the following error:
TypeError: Do not know how to serialize a BigInt
After digging in, it seems that some values in my Prisma response include BigInt, which causes JSON.stringify() to fail. I've implemented the following serializer in order to conver these values from BigInt into string:
// Custom JSON serializer to handle BigInt values
const customJsonSerializer = (data: any) => {
return JSON.stringify(data, (_, value) =>
typeof value === "bigint" ? value.toString() : value
);
};
However, I wonder: Is there anything built into Prisma (or recommended by the team) to help convert BigInt into a JSON-safe format like string? Or is writing a custom serializer the best approach?
Thanks in advance for your help!