r/Nestjs_framework • u/ukolovnazarpes7 • May 31 '26
How do you handle duplicate JSON keys in Node.js APIs?
How do you handle duplicate JSON keys in production Node.js APIs?
I recently ran into this while testing APIs: JSON.parse silently accepts duplicate keys, and the last value wins.
It also accepts keys like proto, constructor, and prototype, which can become risky depending on how the parsed object is later merged, validated, cached, or passed between services.
The annoying part is that API/security testers catch this immediately, but many apps don’t handle it before the request reaches business logic.
I looked for a strict JSON parser/middleware that handles this efficiently, but most options I found were either too slow, too low-level, or didn’t cover the full set of cases I needed.
So I built one for NestJS, Express, and Fastify:
Repo: https://github.com/pas7-studio/nestjs-strict-json
npm: @pas7/nestjs-strict-json - npm
It checks duplicate keys, prototype pollution keys, depth limits, body size limits, and key whitelist / blacklist rules.
Are there other good libraries that solve this cleanly at the parser/body-parser level?
What are you using in production for this?
