Case A
Inspect an order response, then review its types and schema
An order response mixes long string IDs, null coupons and a retryable field present on only one order. Making it readable and checking its runtime contract are different tasks. Carry the full nested response into a schema, then test what it accepts.
Use JSON Formatter and JSON to TS/Zod. Set the root name to OrderBatch and leave All Optional off. Step 3 runs separately in Node/Zod; the web converter does not execute schemas.
1. Parse the response and inspect its structure
Paste the input into Formatter and select Format. Check that order IDs remain quoted strings, coupon retains null, and the missing retryable field is not invented.
JSON Formatter →Step input or application code
{"requestId":"case-42","orders":[{"id":"9007199254740995","total":12900,"coupon":null},{"id":"9007199254740996","total":0,"coupon":"WELCOME","retryable":false}]}Execution result or applied output
{
"requestId": "case-42",
"orders": [
{
"id": "9007199254740995",
"total": 12900,
"coupon": null
},
{
"id": "9007199254740996",
"total": 0,
"coupon": "WELCOME",
"retryable": false
}
]
}The output uses two-space indentation and preserves field order and string IDs. Compare it below, then use the TS/Zod transfer button on the current valid result. After editing input, process it again.
2. Transfer the complete response and compare the Type tab
Use Formatter’s TS/Zod button. The formatted JSON is handed over and removed from tab storage after reading. Change the root name to OrderBatch and select TS Type. If opening the converter directly, paste the formatted input below.
JSON to TS/Zod →Step input or application code
{
"requestId": "case-42",
"orders": [
{
"id": "9007199254740995",
"total": 12900,
"coupon": null
},
{
"id": "9007199254740996",
"total": 0,
"coupon": "WELCOME",
"retryable": false
}
]
}Execution result or applied output
export type OrderBatch_ordersItem = {
"id": string;
"total": number;
"coupon": null | string;
"retryable"?: boolean;
};
export type OrderBatch = {
"requestId": string;
"orders": (OrderBatch_ordersItem)[];
};Across the nested order samples, coupon becomes a string or null and retryable an optional boolean. This merges observed response shapes; it does not guarantee the full API contract.
3. Run the generated Zod schema against a mismatch
Use the Zod Schema output in a separate Node project. The complete example below appends safeParse calls for the original sample and a response whose total is a string. It was executed with the repository’s installed Zod 4 to obtain the output on the right.
Step input or application code
import { z } from 'zod';
export const OrderBatch_ordersItemSchema = z.object({
"id": z.string(),
"total": z.number(),
"coupon": z.union([z.null(), z.string()]),
"retryable": z.boolean().optional(),
});
export const OrderBatchSchema = z.object({
"requestId": z.string(),
"orders": z.array(OrderBatch_ordersItemSchema),
});
const sample = {
"requestId": "case-42",
"orders": [
{
"id": "9007199254740995",
"total": 12900,
"coupon": null
},
{
"id": "9007199254740996",
"total": 0,
"coupon": "WELCOME",
"retryable": false
}
]
};
const mismatched = {
"requestId": "case-43",
"orders": [
{
"id": "9007199254740997",
"total": "12900",
"coupon": null
}
]
};
console.log(OrderBatchSchema.safeParse(sample).success);
console.log(OrderBatchSchema.safeParse(mismatched).success);Execution result or applied output
true
falseThe results are true, then false. This verifies runtime rejection, but not business rules such as currency, valid amounts or whether an order ID exists.
When it fails: reproduce and recover
Formatting fails on a trailing comma
{"requestId":"case-42","orders":[],}Remove the final comma after orders and format again. Errors block copying or transferring the previous result. Hand over the corrected, current result rather than the invalid original.
A numeric total changes to a string
{
"requestId": "case-43",
"orders": [
{
"id": "9007199254740997",
"total": "12900",
"coupon": null
}
]
}The schema generated from the original numeric sample rejects this response. Compare the server contract and response to fix the cause. Re-generating from only this bad sample would infer a string instead of discovering the contract error for you.
Keep exact IDs as strings because JavaScript numbers have precision limits. Zod strips unknown keys by default, and business rules need additional validation. Type generation cannot fix a 401 authentication failure. The related JWT tool inspects time claims and does not verify signatures.