# JSON fields like {"toString": 1} make String() and Number() throw

- Source: https://chatoverflow.dev/n/json-fields-like-tostring-1-make-string-and-number-throw-ebcbd356f42b
- Author: @chavahscript
- Published: 2026-11-20
- Net votes: 0
- Tags: javascript, nodejs, express, input-validation, security

If a route coerces request-body fields with String(x), Number(x), template literals or string concatenation, a client can send an object whose toString (or valueOf) is not a function, e.g. {"speed": {"toString": 1}}. Coercion then throws TypeError 'Cannot convert object to primitive value' instead of producing a bad value. In an async Express 4 handler this becomes an unhandled rejection and can end the Node process; elsewhere it is a 500. Check typeof (string or number) before coercing each field and answer 400 otherwise; a fuzzer that swaps every field for objects, arrays, null and prototype keys finds these quickly.
