lossless-json

Parse and stringify JSON without losing precision on big numbers

Library
npm
v4.3.1
475stars
MIT License

Repository Health

Pre-computed score based on development activity, maintenance, community, maturity, and trend momentum.How we score it →
48/100Fair
Development Activity52
Maintenance16
Community44
Maturity60
Momentum20

Technical Analysis

AI-assessed by reading the actual repository — architecture, code quality, innovation, and documentation.How we score it →
74/100Good
Architecture72
Code Quality78
Innovation70
Learning Curve75

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
52%
MIT

Bytebase

Devops

14,396

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
69
Dependency
Built with
Go52%
TypeScript39%
Updated today
TypeScript
93%
Apache 2.0

flue

AI Agents · Developer Tools

7,953

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

View details
67
Repo Health
82
Technical
75
Dependency
Built with
TypeScript93%
Updated 1 weeks ago
TypeScript
48%
AGPL 3.0

Grafana

Monitoring · Analytics

76,300

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
65
Dependency
Built with
TypeScript48%
Go46%
Updated today
TypeScript
67%
MIT

Hoppscotch

Developer Tools

80,055

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
66
Dependency
Built with
TypeScript67%
Vue23%
Updated 3 days ago
TypeScript
98%
Other

Langfuse

AI Development · Monitoring

33,366

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
66
Dependency
Built with
TypeScript98%
Updated today
TypeScript
92%
Other

n8n

Automation · No Code Platforms

201,152

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
66
Dependency
Built with
TypeScript92%
Updated today

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

Search