lossless-json
Parse and stringify JSON without losing precision on big numbers
Repository Health
Technical Analysis
lossless-json is a drop-in alternative to the native JSON.parse and JSON.stringify that never silently corrupts numeric data. Where JavaScript’s built-in JSON parser converts every number to a 64-bit float, truncating large integers and losing exact decimal formatting, lossless-json parses numbers into a LosslessNumber wrapper that preserves the original string representation until you explicitly convert it.
This makes it well suited for JSON payloads originating from languages like Java, C#, or C++ that routinely carry 64-bit longs or high-precision decimals beyond what a JavaScript number can safely represent. The library also throws on duplicate keys by default and lets you plug in a custom number parser to target bigint, a BigNumber library, or a mix of numeric types, all while remaining API-compatible with the native JSON object.
What You Get
- Drop-in
parse/stringifyfunctions API-compatible with native JSON - LosslessNumber class that preserves big integers, big decimals, and original formatting
- Pluggable
numberParserto target bigint, BigNumber, or custom numeric types - Built-in
isSafeNumber/isIntegerhelpers for validating numeric conversions - Configurable
onDuplicateKeyhandling instead of silent key overwriting - Small footprint (under 4kB minified and gzipped) with full TypeScript typings
Common Use Cases
- Parsing JSON payloads from Java/C#/C++ backends that emit 64-bit longs or high-precision decimals
- Round-tripping JSON through a service without corrupting numbers you don’t otherwise inspect
- Converting parsed numbers into bigint or a BigNumber library for precise arithmetic
- Detecting and rejecting duplicate JSON object keys during ingestion
Under The Hood
Architecture - The library implements a hand-written recursive-descent JSON parser (parse.ts) based on a known character-code-driven technique, walking the input string with an index cursor rather than relying on JSON.parse’s reviver hook, so every numeric token is captured as a raw string and handed to a pluggable numberParser before being wrapped in a LosslessNumber (LosslessNumber.ts); stringify.ts mirrors this by serializing LosslessNumber instances back to their original text. Tech Stack - Written in TypeScript with zero runtime dependencies, built via Babel (ESM) and Rollup (UMD) into lib/esm and lib/umd, linted/formatted with Biome, and versioned with standard-version; the published bundle is under 4kB minified and gzipped. Code Quality - Vitest-based unit tests (*.test.ts) sit alongside each source file (parse, stringify, LosslessNumber, utils, index) covering round-trip parsing, duplicate-key handling, and number-safety edge cases; the codebase is small, single-purpose, and consistently typed with no any escape hatches evident in the core parse/stringify path. API Design - The public API is intentionally a near-exact mirror of the native JSON.parse/JSON.stringify signatures (same reviver/replacer arguments), which minimizes the learning curve for adopters and makes the library a low-friction drop-in replacement; customization (number parsing, duplicate-key policy) is exposed via a small, well-documented options object rather than subclassing or config files.
Used by 6 apps in this directory
Bytebase
Devops
An open-source database CI/CD and DevSecOps platform — schema migration review, GitOps-driven changes, data masking, and access control across MySQL, PostgreSQL, Oracle, Snowflake, MongoDB, and more.
flue
AI Agents · Developer Tools
Build autonomous AI agents and powerful workflows with a programmable TypeScript harness that gives any model sessions, tools, sandboxes, and durable execution.
Grafana
Monitoring · Analytics
The open-source observability platform that unifies metrics, logs, and traces from any data source into dynamic, queryable dashboards.
Hoppscotch
Developer Tools
A lightweight, offline-capable API development ecosystem for testing HTTP, GraphQL, WebSocket, MQTT, and SSE endpoints across web, desktop, and CLI.
Langfuse
AI Development · Monitoring
Open source AI engineering platform for LLM observability, prompt management, evaluation, and debugging — self-host in minutes or use Langfuse Cloud.
n8n
Automation · No Code Platforms
Code when you need it, UI when you don't — the workflow automation platform built for technical teams who refuse to choose.