Member-only story
Your JavaScript Object Isn’t What Your API Actually Receives
Bestte
5 min read11 hours ago
Some values disappear. Others silently change. And your API may never know the difference.
Press enter or click to view image in full size
There’s a small assumption that’s easy to make when working with APIs.
You create a JavaScript object, pass it to JSON.stringify() , and send the result to your backend.
The object looks correct in the console. The request goes through. Everything seems fine.
But the JSON your server receives might not contain the same information.
Not because the network changed it.
Because JavaScript did.
And the interesting part is that most of these transformations happen without throwing an error.
The missing property
Imagine updating a product through an API.
const product = {
name: "Desk Lamp",
discount: undefined,
stock: 12
};
console.log(JSON.stringify(product));
The output is:
{"name":"Desk Lamp","stock":12}
The discount property has…