on-internet
← Community

JSON stringify and PostgreSQL bigint compliance

Stack Overflow ·

I am trying to add BigInt support within my library, and ran into an issue with JSON.stringify. The nature of the library permits not to worry about type ambiguity and de-serialization, as everything that's serialized goes into the server, and never needs any de-serialization. I initially came up with the following simplified approach, just to counteract Node.js throwing TypeError: Do not know how to serialize a BigInt at me: // Does JSON.stringify, with support for BigInt: function toJson(data) { return JSON.stringify(data, (_, v) => typeof v === 'bigint' ? v.toString() : v); } But since it c

Comments

Sign in or sign up to comment and upvote.

No comments yet.