<!-- mobian-agent-page publisher="dailydev" canonical="https://daily.dev/posts/qmmflnosl" -->

---
title: Encode, don&#x27;t stringify - how JSON.stringify lies to you
description: JSON.stringify silently corrupts data (Infinity/NaN become null, undefined keys vanish, Maps and Sets lose data, BigInt throws), leaks undeclared fields, and...
canonical: https://daily.dev/posts/qmmflnosl
twitter:card: summary_large_image
twitter:site: @dailydotdev
og:type: website
og:site_name: daily.dev
og:title: Encode, don&#x27;t stringify - how JSON.stringify lies to you | daily.dev
og:description: JSON.stringify silently corrupts data (Infinity/NaN become null, undefined keys vanish, Maps and Sets lose data, BigInt throws), leaks undeclared fields, and...
og:url: https://daily.dev/posts/qmmflnosl
og:image: https://api.daily.dev/og/posts/qMMFlnOSl.png
og:image:alt: Post cover image
og:image:width: 1200
og:image:height: 630
og:locale: en
---

> ## Documentation Index
> Fetch the complete documentation index at: https://daily.dev/llms.txt
> Use this file to discover all available pages before exploring further.

# Encode, don't stringify - how JSON.stringify lies to you

**[JS Development](https://daily.dev/sources/jsdevelopment)** · [@user45613](https://daily.dev/user45613) · 30 upvotes · 5 comments

## Summary

JSON.stringify silently corrupts data (Infinity/NaN become null, undefined keys vanish, Maps and Sets lose data, BigInt throws), leaks undeclared fields, and gives unhelpful error messages without a path. The proposed fix is 'encode, don't stringify' - using a schema-driven encoder instead of raw JSON.stringify, similar to how 'parse, don't validate' fixed input handling. The piece surveys existing solutions (compile-json-stringify, json-accelerator, devalue, superjson, typia, fast-json-stringify, Zod codecs, Effect Schema) comparing correctness, bundle size, and performance, and presents Sury, the author's own schema library, as the fastest and most complete option with benchmarks and code examples.

## Full article

daily.dev links to this article rather than hosting it. Read it at the original source: <https://dev.to/dzakh/encode-dont-stringify-how-jsonstringify-lies-to-you-38fk>

## Community discussion

Top comments from developers on daily.dev.

**@jenueldev** · 1 upvotes

> The comparison to ‘parse, don’t validate’ is useful because it reframes serialization as a boundary contract rather than a convenience call. I’d also be curious how schema-driven encoders handle versioning when producers and consumers deploy independently, since correctness at one schema version can still hide compatibility failures.

**@agustinbarrientos** · 1 upvotes

> I know I'd blame everything except JSON before noticing that `Infinity` had quietly become `null`

**@andruhudz** · 0 upvotes

> Really nice spot about data conversion. At least we "can use" BigInt in JSON

## Similar posts on daily.dev

- [Governing Security in the Age of Infinite Signal](https://daily.dev/posts/governing-security-in-the-age-of-infinite-signal-qhihbir44) · Snyk · 0 upvotes · 0 comments
- [No one has a good plan for how AI companies should work with the government](https://daily.dev/posts/no-one-has-a-good-plan-for-how-ai-companies-should-work-with-the-government-nkajqoze1) · TechCrunch · 0 upvotes · 1 comments

---

Tags: [#javascript](https://daily.dev/tags/javascript), [#typescript](https://daily.dev/tags/typescript)

[View this post on daily.dev](https://daily.dev/posts/qmmflnosl)

```json
{"@context":"https://schema.org","@graph":[{"@type":"Organization","@id":"https://daily.dev/#organization","name":"daily.dev","url":"https://daily.dev","logo":{"@type":"ImageObject","url":"https://daily.dev/apple-touch-icon.png","width":180,"height":180},"sameAs":["https://twitter.com/dailydotdev","https://github.com/dailydotdev","https://www.linkedin.com/company/daily-dev-ltd"]},{"@type":"WebSite","@id":"https://daily.dev/#website","url":"https://daily.dev","name":"daily.dev","publisher":{"@id":"https://daily.dev/#organization"},"potentialAction":{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https://daily.dev/search?q={search_term_string}"},"query-input":"required name=search_term_string"}}]}
{"@context":"https://schema.org","@type":"DiscussionForumPosting","mainEntityOfPage":"https://daily.dev/posts/qmmflnosl","headline":"Encode, don't stringify - how JSON.stringify lies to you","text":"Shared: Encode, don't stringify - how JSON.stringify lies to you","url":"https://daily.dev/posts/qmmflnosl","datePublished":"2026-09-02T19:18:46.484Z","dateModified":"2026-09-02T19:18:46.493Z","author":{"@type":"Person","name":"Veselin Ivanov","url":"https://daily.dev/user45613","image":"https://media.daily.dev/image/upload/s--nc0o8dM8--/f_auto/v1782457323/avatars/avatar_JYf2mTyl8QY4B2HJp3soD?_a=BAMAMicg0","description":"you don’t rise to the level of your expectations, you fall to the level of your training","interactionStatistic":{"@type":"InteractionCounter","interactionType":{"@type":"EndorseAction"},"userInteractionCount":630}},"image":"https://media.daily.dev/image/upload/s--2-1xRawN--/f_auto/v1722860399/public/Placeholder%2011","interactionStatistic":[{"@type":"InteractionCounter","interactionType":{"@type":"LikeAction"},"userInteractionCount":30},{"@type":"InteractionCounter","interactionType":{"@type":"CommentAction"},"userInteractionCount":5}],"sharedContent":{"@type":"WebPage","url":"https://api.daily.dev/r/HiwS9KoBw"},"comment":[{"@type":"Comment","text":"The comparison to ‘parse, don’t validate’ is useful because it reframes serialization as a boundary contract rather than a convenience call. I’d also be curious how schema-driven encoders handle versioning when producers and consumers deploy independently, since correctness at one schema version can still hide compatibility failures.","datePublished":"2026-09-03T04:38:42.503Z","url":"https://daily.dev/posts/qMMFlnOSl#c-GDArjwDGo","author":{"@type":"Person","name":"Jenuel Oras Ganawed","url":"https://daily.dev/jenueldev","image":"https://media.daily.dev/image/upload/s--BadmiNyj--/f_auto/v1787625077/avatars/avatar_JJtZr4Sjm?_a=BAMAMicg0"},"interactionStatistic":{"@type":"InteractionCounter","interactionType":{"@type":"LikeAction"},"userInteractionCount":1}},{"@type":"Comment","text":"I know I’d blame everything except JSON before noticing that Infinity had quietly become null","datePublished":"2026-09-04T21:25:20.070Z","url":"https://daily.dev/posts/qMMFlnOSl#c-cDWJX5bib","author":{"@type":"Person","name":"Agustin Barrientos","url":"https://daily.dev/agustinbarrientos","image":"https://media.daily.dev/image/upload/s--5ayxQnqn--/f_auto/v1788281802/avatars/avatar_wQYYVe5Tbj0NJ7C7qPoa8?_a=BAMAMicg0"},"interactionStatistic":{"@type":"InteractionCounter","interactionType":{"@type":"LikeAction"},"userInteractionCount":1}},{"@type":"Comment","text":"Really nice spot about data conversion. At least we “can use” BigInt in JSON","datePublished":"2026-09-13T19:58:37.606Z","dateModified":"2026-09-13T20:01:27.144Z","url":"https://daily.dev/posts/qMMFlnOSl#c-xujEZvK5c","author":{"@type":"Person","name":"andru hudz","url":"https://daily.dev/andruhudz","image":"https://lh3.googleusercontent.com/a/ACg8ocL---snYLZfyby0hGSZRNE0HBZxFUaV8F3aRsSy8J8sc6V6Ew=s96-c"}}],"isPartOf":{"@type":"WebPage","url":"https://daily.dev/squads/jsdevelopment","name":"JS Development"}}
{"@context":"https://schema.org","@type":"BreadcrumbList","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https://daily.dev"},{"@type":"ListItem","position":2,"name":"JS Development","item":"https://daily.dev/squads/jsdevelopment"},{"@type":"ListItem","position":3,"name":"Encode, don't stringify - how JSON.stringify lies to you"}]}
```

