{"title":"Review Required Fields in a Generated JSON Schema","excerpt":"A schema inferred from one successful response may reject valid variants. Use the generator for observed types, then review required fields and closed-object rules against the API contract.","canonicalUrl":"https://automationtester.in/blog/tools-reviews/review-generated-json-schema-required-fields","category":{"name":"Tools & Reviews","slug":"tools-reviews"},"tags":["json-schema","api-contracts","json","validation"],"author":{"name":"Shashank Rawlani","url":"https://shashank.rawlani.com","linkedin":"https://www.linkedin.com/in/shashankrawlani/"},"datePublished":"2026-10-11T05:30:00.000Z","dateModified":"2026-10-14T10:26:49.548Z","coverImage":{"url":"https://ik.imagekit.io/automationtester/automationtester-in/blog/covers/v3/review-generated-json-schema-required-fields.webp","alt":"Three green field rows leave one sample object and enter a dashed schema box as required rows. A separate orange row, absent from the sample, stops at a crossed-out marker before the schema box."},"contentHtml":"<div class=\"callout callout-info\"> Paste one representative JSON response into the <a href=\"https://automationtester.in/tools/json-schema\">JSON to Schema Generator</a> to get a Draft 2020-12 starting point. Review <code>required</code> and <code>additionalProperties</code> before using it as a contract. One example cannot tell you which fields are optional across all valid responses.</div>\n\n<p>A response from a successful request contains every field. A schema inferred from that one response may reject a perfectly valid response from an older account with no profile data. The generator can identify observed types; it cannot infer the API's full rules from one instance.</p>\n\n<h2 id=\"schema-one-example\">Generate from a small response</h2>\n\n<p>Open the tool, replace the sample with this JSON, leave “Required fields” checked, and leave “Allow additional properties” unchecked:</p>\n\n<pre class=\"language-json\"><code class=\"language-json\">{\"status\":\"paid\",\"amount\":499,\"roles\":[\"sdet\"]}</code></pre>\n<a href=\"https://automationtester.in/tools/json-schema#p=eyJ2IjoxLCJpbnB1dCI6IntcInN0YXR1c1wiOlwicGFpZFwiLFwiYW1vdW50XCI6NDk5LFwicm9sZXNcIjpbXCJzZGV0XCJdfSJ9\">Try this in JSON to Schema Generator</a>\n\n<p>The generated object has <code>status</code> as a string, <code>amount</code> as an integer, and <code>roles</code> as an array of strings. It lists all three keys in <code>required</code> and sets <code>additionalProperties</code> to <code>false</code>. The <code>$schema</code> value names Draft 2020-12.</p>\n\n<p>Those choices are visible decisions, not facts established by the sample. If <code>roles</code> can be omitted, remove it from <code>required</code>. If the API allows new response fields, turn on “Allow additional properties” or edit that rule after copying. JSON Schema defines <code>required</code> as property presence and <code>additionalProperties</code> as a rule for names outside those declared in <code>properties</code>.</p>\n\n<h2 id=\"schema-observed-values\">Types are evidence; business rules need review</h2>\n\n<p>The observed string <code>\"paid\"</code> becomes <code>{\"type\":\"string\"}</code>. It does not become an enum, so the schema would also accept <code>\"unknown\"</code> unless you add an allowed-value rule. The number <code>499</code> becomes an integer, but the generator does not know whether negative amounts are forbidden or what unit the amount uses.</p>\n\n<p>Array inference examines the elements it sees. An empty array gives the generator no item type to learn. Try a response with several valid shapes, then edit the schema against the actual API contract. <a href=\"https://automationtester.in/tools/json-diff\">JSON Diff</a> can help find fields that changed across two captured responses, but neither tool replaces contract review. If the schema is headed for an MCP tool's <code>outputSchema</code>, paste the tool definition into the <a href=\"https://automationtester.in/tools/mcp-tool-schema-checker\">MCP Tool Schema Checker</a> too; it reports <code>required</code> names that no longer match a property.</p>\n\n<p><strong>Does the generator validate my API?</strong> No. It produces a schema document from an example. Run that schema through a validator against separate positive and negative fixtures. When the JSON comes from a language model rather than an API, the reviewed schema can become a promptfoo <code>is-json</code> assertion; the <a href=\"https://automationtester.in/tools/llm-eval-case-builder\">LLM Eval Test-Case Builder</a> writes it into the config as a mapping.</p>\n\n<p><strong>Should every observed field be required?</strong> Only if the contract says it must always appear. The checkbox expresses a starting assumption, not a discovery.</p>\n\n<h2 id=\"schema-apply\">Review the contract before CI</h2>\n\n<p>Generate a schema from one real response. Mark every required field and closed-object rule that came from the sample alone. Check those decisions against the API specification or at least two contrasting fixtures before adding the schema to CI.</p>\n\n<h2 id=\"schema-references\">Schema specification and tool reference</h2>\n<ul>\n<li><a href=\"https://json-schema.org/draft/2020-12/json-schema-validation\">JSON Schema Draft 2020-12 Validation</a>: meanings of <code>type</code>, <code>required</code>, and <code>additionalProperties</code>.</li>\n<li><a href=\"https://automationtester.in/tools/json-schema\">AutomationTester.in JSON to Schema Generator</a>: input, options, and generated output.</li>\n</ul>\n"}