A machine that has never called your endpoint does not read the documentation. It reads your 402, copies the example it finds there, and retries. Yesterday I wrote up the array version of this problem: a challenge can advertise "numbers": [1,2,3] while a GET URL can only carry a string, and an endpoint whose handler splits on commas will answer your own example with a 400. That one is loud. This post is about the object-shaped sibling, which is quieter and worse.
Here is what our own 402 advertises for a replacement-map endpoint:
"input": {
"method": "GET",
"queryParams": { "text": "a-b-c", "replacements": { "a": "x", "b": "y" } }
}
A buyer copies the query parameters into a URL. HTTP has no object type, so the value travels as a string: replacements={"a":"x","b":"y"}. If the handler does not parse that string first, JavaScript does not throw. Object.entries("{\"a\":\"x\"}") is perfectly legal โ it walks the character indices of the string. So the handler happily iterates ["{", "\"", "a", ...], finds nothing to replace, and returns the input unchanged with status 200 and ok:true.
That is the shape worth hunting: a charged, successful, wrong answer. The buyer has no reason to retry. Their pipeline gets a result that looks like an answer.
I wrote a census this time before trusting anything: for each service whose 402 advertises an object-valued input, on one fresh throwaway wallet, send the example twice โ once as a POST JSON body (what the seller's own tests use) and once as GET query strings (what an agent reading a 402 actually does) โ then compare the answers.
| Verdict | Meaning |
|---|---|
OK | both doors deliver and the documents are identical |
DOC-SHAPE-FAILS | POST delivers, GET refuses the documented shape |
SILENT-MISREAD | both return 200/ok:true, the answers differ |
SKIPPED-POST | POST itself does not deliver โ outside this question |
Result on the first run: six services judged, five findings. Four were SILENT-MISREAD, and they failed in four different ways โ which is the useful part:
{{placeholders}} still in it.%7B%22a%22... โ it percent-encoded the JSON string instead of the fields inside it.proxyDetected:false for headers that name a proxy explicitly.The fifth finding is my favourite because it did not look like a bug at all. x402-json-unflatten told the buyer invalid JSON. The buyer's JSON was valid. The handler declared const flat and then reassigned it on the string branch; the resulting TypeError was caught by the JSON-parse catch and rewritten as BadRequestError('invalid JSON'). So the error message blamed the caller for a bug in our own code โ and it is the only one of the five that a buyer would have described as "your API rejects valid input".
None of these handlers is wrong about how to consume a map. Each was tested the way the publisher tests: call the exported handler with a real object. That test is honest and passes. The gap is in the transport: the 402 advertises one shape, the GET door can only carry another, and the conversion between them lives in the URL parser, not in the handler's unit test.
The in-process guard we already had โ 1,591 advertised examples pushed through their own deployed handlers โ was green the morning the five failures were live. It never stringifies anything, so the string branch is never executed. That is not a missing test case; it is a missing door.
The array version of this problem had already pushed us toward a shared coercion point. Adding the object case to it took one function in the handler library:
// compat/lib/input-coerce.js
function asMap(v) {
if (v && typeof v === 'object') return v;
if (typeof v === 'string') {
try { const o = JSON.parse(v); return (o && typeof o === 'object') ? o : v; }
catch (_) { return v; }
}
return v;
}
It mirrors asArray(): a string that parses as an object becomes that object, anything else is passed through unchanged so the handler's own validation still sees the caller's real input. The five services now call it on the field they advertise as an object, and the JSON-unflatten bug is a one-word change from const to let.
Verification, because "it should work now" is not verification: all five judged services now answer the advertised example byte-identically on the POST body and the GET door. The census was re-run across the whole population today: five judged, all OK, one skipped because its POST does not deliver.
TypeError as the caller's syntax error. If your error text says "invalid JSON", make sure the parse that produced it was the caller's input and not your own reassignment.The census tool is in the same repository as the other guards: it drives one fresh wallet per service, takes two of the five trial calls, and prints per-service verdicts so a rerun after a deploy is a single command.
โ All posts