Skip to content

In development. Expect rough edges and changes. The source code is not public yet.

Neon 12 min read Deep dive mediumAdept

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

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.

Related posts

  • @clickhouse/rowbinary: when your library is also a parser compiler

    ClickHouse mediumAdept

    @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. Generated parsers ran 1.5–3.4x faster than composing the library API (e.g. one bounds check and constant-offset reads for fixed-width rows, avoiding V8 megamorphic dispatch), and RowBinary itself beat the correct BigInt-safe JSON path by 2.1–3.3x on numeric schemas, though JSONCompactEachRow wins on string-heavy data. Each parser costs about $0.20 to generate with Claude Sonnet 4.6, and grounding the agent in tested primitives avoids silent bugs such as byte-order-wrong UUID decoding that models produced from memory in 3 of 5 runs.

  • Bun v0.6.2

    Bun easyNovice

    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. Microbenchmarks on an M1 Max show JSON.parse dropping from 1.45µs to 1.1µs, versus 2.44µs on Node 20. It also fixes a minifier bug with rope strings in template literals, a bundler bug where imported assets were never copied to the output directory, and a bug where warnings incorrectly failed builds.

  • @neondatabase/serverless hits 1.0.0

    Neon mediumAdept

    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. Tagged-template queries are now composable, because placeholder numbering is deferred until execution. A breaking change makes calling sql(...) as a plain function an error, since that form used ordinary string interpolation and invited SQL injection. New sql.query and sql.unsafe helpers cover the parameterized and trusted-raw-SQL cases. Binary inserts over HTTP now hex-encode roughly 10x faster, though WebSockets remain the recommended path for large blobs.

  • Bloom filters: the niche trick behind a 16× faster API

    incident.io mediumAdept

    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. Attribute key-value pairs are string-encoded, hashed with seven hash functions into a 512-bit bitmap stored as a bit(512) column, and queried with bitwise AND against bitmasks. With a 1% false-positive rate, only about 1% of the previous in-memory deserialization work remains. The bottleneck had been fetching and deserializing 500-row batches into Go structs. The team spiked a GIN index with jsonb_path_ops as the alternative and benchmarked both options before choosing.

  • pg_jsonschema: JSON Schema support for Postgres

    Supabase mediumAdept

    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`. Used inside a check constraint, it keeps the flexibility of document columns, such as storing raw webhook payloads instead of normalizing them into many joined tables, while still enforcing type, required-field and no-extra-properties rules. In the example, an unconstrained `json` column handled only 2 of 8 test inputs correctly, and the schema-backed check constraint handled all 8. It is available on Supabase via `create extension pg_jsonschema` or through Docker Compose.

The quest for software engineering knowledge.

Look:
Layout: