lossless-json

Parse and stringify JSON without losing precision on big numbers

Library
npm
v4.3.1
476 stars
MIT License

Repository Health

Pre-computed score based on development activity, maintenance, community, maturity, and trend momentum. How we score it →
44 /100 Fair
Development Activity 36
Maintenance 16
Community 44
Maturity 60
Momentum 20

Technical Analysis

AI-assessed by reading the actual repository — architecture, code quality, innovation, and documentation. How we score it →
74 /100 Good
Architecture 72
Code Quality 78
Innovation 70
Learning Curve 75

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/stringify functions API-compatible with native JSON
  • LosslessNumber class that preserves big integers, big decimals, and original formatting
  • Pluggable numberParser to target bigint, BigNumber, or custom numeric types
  • Built-in isSafeNumber/isInteger helpers for validating numeric conversions
  • Configurable onDuplicateKey handling 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

Go
49%
MIT

Bytebase

Devops

14,512

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.

View details
92
Repo Health
73
Technical
68
Dependency
Built with
Go 49%
TypeScript 42%
Updated 4 days ago
TypeScript
94%
Apache 2.0

flue

AI Agents · Developer Tools

8,383

Build autonomous AI agents and powerful workflows with a programmable TypeScript harness that gives any model sessions, tools, sandboxes, and durable execution.

View details
80
Repo Health
82
Technical
70
Dependency
Built with
TypeScript 94%
Updated 1 weeks ago
TypeScript
48%
AGPL 3.0

Grafana

Analytics · Monitoring

76,962

The open-source observability platform that unifies metrics, logs, and traces from any data source into dynamic, queryable dashboards.

View details
95
Repo Health
91
Technical
63
Dependency
Built with
TypeScript 48%
Go 46%
Updated 4 days ago
TypeScript
67%
MIT

Hoppscotch

Developer Tools

80,529

A lightweight, offline-capable API development ecosystem for testing HTTP, GraphQL, WebSocket, MQTT, and SSE endpoints across web, desktop, and CLI.

View details
91
Repo Health
83
Technical
65
Dependency
Built with
TypeScript 67%
Vue 25%
Updated 6 days ago
TypeScript
97%
Other

Langfuse

AI Development · Monitoring

35,117

Open source AI engineering platform for LLM observability, prompt management, evaluation, and debugging — self-host in minutes or use Langfuse Cloud.

View details
92
Repo Health
81
Technical
65
Dependency
Built with
TypeScript 97%
Updated 4 days ago
TypeScript
92%
Other

n8n

Automation · No Code Platforms

206,147

Code when you need it, UI when you don't — the workflow automation platform built for technical teams who refuse to choose.

View details
95
Repo Health
87
Technical
65
Dependency
Built with
TypeScript 92%
Updated 4 days ago

Join founders buildingwith open source

Opinionated takes, migration guides, cost-saving tips, and insights from the open source ecosystem.

Subscribe on Substack
Join 750+ subscribers