---
title: "Parsing JSON from Postgres in JS? Don’t get the wrong number"
description: "JavaScript's JSON.parse() silently corrupts Postgres bigint and numeric values beyond Number.MAX_SAFE_INTEGER, so a row id can quietly become a different id."
url: "https://swe.quest/articles/parsing-json-from-postgres-in-js-don-t-get-the-wrong-number-5e25d42dfaa1da08"
canonical: "https://neon.com/blog/parsing-json-from-postgres-in-js"
source: "Neon"
published: "2023-08-24"
difficulty: "medium"
kind: "Deep dive"
reading_minutes: 12
tags: ["javascript","postgres","performance","runtimes"]
---

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

A post on [Neon](https://swe.quest/sources/neon.md), published 2023-08-24, 12 min read, Deep dive. Original: [https://neon.com/blog/parsing-json-from-postgres-in-js](https://neon.com/blog/parsing-json-from-postgres-in-js)

## Summary

JavaScript's JSON.parse() silently corrupts Postgres bigint and numeric values beyond Number.MAX\_SAFE\_INTEGER, so a row id can quietly become a different id. The fix is a custom JSON parser registered with node-postgres or Neon's serverless driver; the reviver argument can't help because numbers are already float64 by then. json-custom-numbers is introduced as a drop-in replacement that matches JSON.parse() on the JSON Parsing Test Suite, supports custom number parsing, and runs only 1.5–3× slower than native, versus 4–11× for lossless-json and json-bigint. Lessons from optimizing it: sticky RegExps for primitives, manual inlining, charCodeAt over charAt, a non-recursive state machine to avoid stack overflows, and how JIT warm-up and deoptimization from invalid inputs skew benchmarks.

Written by swe.quest, not by the author.

**Difficulty:** Medium: assumes a working developer; shows how it is built or done

## Topics

- [JavaScript](https://swe.quest/tags/javascript.md) (Languages)
- [PostgreSQL](https://swe.quest/tags/postgres.md) (Data & databases)
- [Performance engineering](https://swe.quest/tags/performance.md) (Reliability & operations)
- [Runtimes & VMs](https://swe.quest/tags/runtimes.md) (Compilers & runtimes)

## Prerequisites

- JSON format
- JavaScript number semantics ([easy posts on JavaScript](https://swe.quest/tags/javascript.md?difficulty=easy))
- node-postgres basics ([easy posts on JavaScript](https://swe.quest/tags/javascript.md?difficulty=easy))

## Keywords

json-custom-numbers, JSON.parse, BigInt, node-postgres, @neondatabase/serverless, lossless-json, json-bigint, V8

## Related posts

- [@clickhouse/rowbinary: when your library is also a parser compiler](https://swe.quest/articles/clickhouse-rowbinary-when-your-library-is-also-a-parser-compiler-a30fc022f9070ed3.md): ClickHouse · 2026-07-14 · Medium · 10 min read · AI for coding, Performance engineering, TypeScript, Analytics & OLAP, Compilers
  @clickhouse/rowbinary is a Node.js reader/writer for ClickHouse's RowBinary formats that also ships as an Agent Skill: a coding agent reads its densely commented, monomorphizable primitives plus SKILL.md and generates a parser specialized to a query's exact column types, replacing a traditional codegen compiler.
- [Bun v0.6.2](https://swe.quest/articles/bun-v0-6-2-b67998d40f2097f2.md): Bun · 2023-05-17 · Easy · 3 min read · JavaScript, Runtimes & VMs, Performance engineering
  Bun v0.6.2 pulls in JavaScriptCore performance work: number toLocaleString() is 79x faster, JSON.parse is up to 20% faster and JSON.stringify 15% faster on shallow objects, Proxy get/set is 2x or more faster, and Object.assign with empty sources and returning arguments are each 2x faster.
- [@neondatabase/serverless hits 1.0.0](https://swe.quest/articles/neondatabase-serverless-hits-1-0-0-d5430675bc92b751.md): Neon · 2025-03-25 · Medium · 5 min read · PostgreSQL, Serverless, TypeScript, Application security, JavaScript
  Neon's JavaScript/TypeScript serverless driver, which carries Postgres queries over HTTP and WebSockets for environments without raw TCP such as V8 isolates and browsers, reaches 1.0.0 after a refactor that adds auto-generated types via api-extractor and CI tests across Node, Bun, Deno, browsers, Cloudflare Workers, Vercel and the Prisma/Drizzle adapters.
- [Bloom filters: the niche trick behind a 16× faster API](https://swe.quest/articles/bloom-filters-the-niche-trick-behind-a-16-faster-api-f8c936f8ee9c7bb2.md): incident.io · 2025-11-14 · Medium · 16 min read · PostgreSQL, Data structures, Performance engineering, API design
  incident.io cut P95 latency of its alert-filtering API for large organisations from 5s to 0.3s by pushing JSONB attribute filters into Postgres using bloom filters.
- [pg\_jsonschema: JSON Schema support for Postgres](https://swe.quest/articles/pg-jsonschema-json-schema-support-for-postgres-489ffe5b7545ddca.md): Supabase · 2022-08-19 · Medium · 4 min read · PostgreSQL, Databases
  pg\_jsonschema is a Postgres extension that validates \`json\` and \`jsonb\` values against a JSON Schema through two functions, \`json\_matches\_schema\` and \`jsonb\_matches\_schema\`.

Browse: [Latest posts](https://swe.quest/index.md) · [Topics](https://swe.quest/tags.md) · [Sources](https://swe.quest/sources.md) · [Topic map](https://swe.quest/map.md) · [Site guide (llms.txt)](https://swe.quest/llms.txt)
