JSON Schema Validation: Why a String Quantity Fails in Valid JSON
An order sends "2" instead of 2. Follow it through a JSON parser and a schema validator to find which check fails, read the error, and fix the right field.

A customer orders two notebooks. The checkout form shows 2, the request body looks right, and your JSON formatter has no complaints. Yet the order API rejects the request: quantity must be integer. If you look at the raw request rather than the form, you can see the problem: the browser sent "2", including the quotes.
A JSON parser asks “What value does this text represent?” A schema validator asks “Is that value allowed here?” There is nothing wrong with "2" as JSON. There is something wrong with using it as the quantity for this order.
Run the same order through both checks
Paste this request into the JSON Validator. It passes. Double quotes around a value are legal; they tell the parser to produce a string. Formatting the object adds whitespace, but it won't change that string into a number.
{ "quantity": "2" }
Now open the JSON Schema Validator. Paste the same request into JSON Data and the schema below into JSON Schema. Leave the draft set to Draft 2020-12 and choose Validate.
{
"type": "object",
"required": ["quantity"],
"properties": {
"quantity": { "type": "integer", "minimum": 1 }
}
}
Look at the three pieces of the error: /quantity is the location in the data, type is the rule that failed, and must be integer is what the rule expected. That's a more useful diagnosis than “invalid JSON”: the parser got far enough to find the property and inspect its value.
Change only the data on the left and validate again. Keep the quotes around the key; remove the quotes around the value:
{ "quantity": 2 }
Read the rule before changing the data
Try replacing the entire input on the left with each of these. All four are valid JSON. The schema doesn't reject them all for the same reason.
| Request body | Result | What the validator found |
|---|---|---|
{} |
required |
The object has no quantity property. |
{ "quantity": null } |
type |
The property exists, but its value is null, not an integer. |
{ "quantity": 0 } |
minimum |
Zero is an integer, but the order must contain at least one item. |
{ "quantity": 2.0 } |
Valid | JSON Schema tests the numeric value. Two has no fractional part. |
Notice where the missing-property error points. For {}, CodeBench shows /, the root object, rather than /quantity. That isn't a different spelling of the original error. There is no child value to point to. The validator reports the missing property on the object that should contain it. Also, properties describes how to check a property if present; the separate required list is what rules out {}.
Fix the producer, not just the example
If you can make the pasted example pass but the next order still fails, inspect the code that builds the request. An HTML number input's .value is a string even when the control displays a number. For a quantity field, read .valueAsNumber, check that the result is a safe integer of at least one, and only then serialize the order. In particular, a blank field is not an order for zero notebooks.
Don't apply that conversion to every field containing digits. A postal code such as "02108" needs its leading zero; treating it as a quantity would change the address. The right fix follows the meaning of the field, not its appearance. And keep the same validation at the API boundary: the form isn't the only client that can send an order.
Next time a payload fails, start with the original request body. If it won't parse, fix the syntax. If it parses, keep the schema fixed, read the path and failed rule, and change one value at a time. That small discipline separates a missing comma from a missing property, and both from a perfectly valid string in the wrong place.