Parsing JSON from Postgres in JS? Don't get the wrong number

This title could be clearer and more informative.Try out Clickbait Shieldfor free (5 uses left this month).

JavaScript's native JSON.parse() silently corrupts large integers (e.g., Postgres bigint values) by converting them to float64, losing precision without any warning. Existing npm packages like json-bigint and lossless-json address this but have conformance gaps and are 4–11× slower than native parsing. The author introduces json-custom-numbers, a new JavaScript JSON parser that fully matches native JSON.parse() behavior, supports custom number-parsing callbacks, and runs only 1.5–3× slower. The post also covers implementation lessons: sticky RegExps for performance, JavaScript engine JIT memory effects on benchmarking, non-recursive parsing via state machine, and the surprising fact that native JSON.stringify() is still recursive.

14m read timeFrom neon.com
Post cover image
Table of contents
Trouble with numbersThe solution: custom JSON parsingConformance and performance testingCan we do better?Presenting: json-custom-numbersWhat I learned
1 Impression