{"id":921,"date":"2026-11-26T15:01:02","date_gmt":"2026-11-26T15:01:02","guid":{"rendered":"https:\/\/html-editor-online.com\/blog?p=921"},"modified":"2026-11-26T15:01:02","modified_gmt":"2026-11-26T15:01:02","slug":"json-schema-validator-python","status":"publish","type":"post","link":"https:\/\/html-editor-online.com\/blog\/json-schema-validator-python\/","title":{"rendered":"JSON Schema Validator in Python: Check Syntax First, Then Validate the Structure"},"content":{"rendered":"\n<p class=\"wp-block-paragraph\">A json schema validator in Python answers a different question from a syntax check. Python first parses the text into data, then the jsonschema package tests that data against rules such as required fields, types and allowed values. The input is a JSON file plus a schema file, and the output is a list of violations with a location and the failed keyword. Before writing any script, I confirm the text is well-formed with the HTML Editor Online <a href=\"https:\/\/html-editor-online.com\/tools\/json_validator\" title=\"JSON Validator\">JSON Validator<\/a>, which checks syntax only. Once the text parses, the Python workflow below tells you exactly what is wrong with the structure and what to fix first.<\/p>\n\n\n\n<div class=\"wp-block-rank-math-toc-block\" id=\"rank-math-toc\"><h2>Table of Contents<\/h2><nav><ul><li class=\"\"><a href=\"#syntax-errors-and-schema-violations-are-different-problems-1\">Syntax errors and schema violations are different problems<\/a><\/li><li class=\"\"><a href=\"#check-the-json-before-you-run-a-json-schema-validator-in-python-2\">Check the JSON before you run a JSON schema validator in Python<\/a><\/li><li class=\"\"><a href=\"#a-small-schema-and-two-data-files-to-test-with-3\">A small schema and two data files to test with<\/a><\/li><li class=\"\"><a href=\"#a-json-schema-validator-in-python-the-full-script-4\">A JSON schema validator in Python: the full script<\/a><\/li><li class=\"\"><a href=\"#read-the-errors-and-decide-what-to-fix-first-5\">Read the errors and decide what to fix first<\/a><\/li><li class=\"\"><a href=\"#limits-to-keep-in-mind-before-you-trust-a-pass-6\">Limits to keep in mind before you trust a pass<\/a><\/li><li class=\"\"><a href=\"#frequently-asked-questions\">Frequently asked questions<\/a><\/li><li class=\"\"><a href=\"#next-steps\">Next steps<\/a><\/li><li class=\"\"><a href=\"#sources\">Sources and further reading<\/a><\/li><\/ul><\/nav><\/div>\n\n\n<div class=\"wp-block-image heo-auto-image\">\n<figure class=\"aligncenter size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"576\" src=\"https:\/\/html-editor-online.com\/blog\/wp-content\/uploads\/2026\/11\/json-schema-validator-python-image-1-879-1-c023d792ac564bcc-1024x576.jpg\" alt=\"Conceptual illustration of two layers, syntax below and structure rules above, for JSON validation\" class=\"wp-image-924\" srcset=\"https:\/\/html-editor-online.com\/blog\/wp-content\/uploads\/2026\/11\/json-schema-validator-python-image-1-879-1-c023d792ac564bcc-1024x576.jpg 1024w, https:\/\/html-editor-online.com\/blog\/wp-content\/uploads\/2026\/11\/json-schema-validator-python-image-1-879-1-c023d792ac564bcc-300x169.jpg 300w, https:\/\/html-editor-online.com\/blog\/wp-content\/uploads\/2026\/11\/json-schema-validator-python-image-1-879-1-c023d792ac564bcc-768x432.jpg 768w, https:\/\/html-editor-online.com\/blog\/wp-content\/uploads\/2026\/11\/json-schema-validator-python-image-1-879-1-c023d792ac564bcc.jpg 1200w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n<\/div>\n\n\n<h2 class=\"wp-block-heading\" id=\"syntax-errors-and-schema-violations-are-different-problems-1\">Syntax errors and schema violations are different problems<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">JSON has two layers of correctness. The first is syntax. <a href=\"https:\/\/www.rfc-editor.org\/info\/rfc8259\/\" title=\"RFC 8259: The JavaScript Object Notation (JSON) Data Interchange Format | RFC Editor\" target=\"_blank\" rel=\"noopener\">RFC 8259<\/a> defines what counts as JSON text: quoted keys, matched brackets, no trailing commas. A parser either accepts the text or fails and reports a position.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">The second layer is structure, described by <a href=\"https:\/\/json-schema.org\/learn\/getting-started-step-by-step\" title=\"Creating your first schema\" target=\"_blank\" rel=\"noopener\">JSON Schema<\/a>. A schema states which properties must exist, what type each value has and which values are allowed. A document can pass the first layer and still fail the second.<\/p>\n\n\n\n<figure class=\"wp-block-table\"><table class=\"has-fixed-layout\"><thead><tr><th>Check<\/th><th>Question it answers<\/th><th>Typical failure<\/th><\/tr><\/thead><tbody><tr><td>Syntax<\/td><td>Can this text be parsed as JSON?<\/td><td>A missing closing brace or a trailing comma<\/td><\/tr><tr><td>Schema<\/td><td>Does the parsed data follow the rules?<\/td><td>A required field is missing, or a number arrives as a string<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\">The order matters because a schema validator needs parsed data. A syntax error stops everything before any schema rule is tested. So fix syntax first, then make sure the schema itself is valid, then fix the data.<\/p>\n\n\n<div class=\"wp-block-image heo-auto-image\">\n<figure class=\"aligncenter size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"576\" src=\"https:\/\/html-editor-online.com\/blog\/wp-content\/uploads\/2026\/11\/json-schema-validator-python-image-2-879-2-067531fabf21f9e7-1024x576.jpg\" alt=\"Developer checking JSON syntax on a laptop before running schema validation\" class=\"wp-image-926\" srcset=\"https:\/\/html-editor-online.com\/blog\/wp-content\/uploads\/2026\/11\/json-schema-validator-python-image-2-879-2-067531fabf21f9e7-1024x576.jpg 1024w, https:\/\/html-editor-online.com\/blog\/wp-content\/uploads\/2026\/11\/json-schema-validator-python-image-2-879-2-067531fabf21f9e7-300x169.jpg 300w, https:\/\/html-editor-online.com\/blog\/wp-content\/uploads\/2026\/11\/json-schema-validator-python-image-2-879-2-067531fabf21f9e7-768x432.jpg 768w, https:\/\/html-editor-online.com\/blog\/wp-content\/uploads\/2026\/11\/json-schema-validator-python-image-2-879-2-067531fabf21f9e7.jpg 1200w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n<\/div>\n\n\n<h2 class=\"wp-block-heading\" id=\"check-the-json-before-you-run-a-json-schema-validator-in-python-2\">Check the JSON before you run a JSON schema validator in Python<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Paste the text into the JSON Validator first. It checks syntax with the browser&#8217;s <code>JSON.parse<\/code> and gives you a normalized copy, with optional key sorting. The <a href=\"https:\/\/html-editor-online.com\/editors\/json\" title=\"JSON Editor\">JSON Editor<\/a> offers the same <code>JSON.parse<\/code> syntax validation along with highlighting, code folding and format or minify, which helps when you want to edit as you fix. Neither tool does JSON Schema validation, and the editor has no tree view. A passing result means only that the text parses.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">If parsing fails, read the reported error and fix it at the source. For common formatting mistakes, <a href=\"https:\/\/html-editor-online.com\/tools\/json_repair\" title=\"JSON Repair\">JSON Repair<\/a> can attempt an automatic fix. Review its output carefully, because a repair can change values, and it cannot recover data that was truncated. Treat it as a way to get a file moving, then correct whatever produced the broken JSON.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">When the JSON parses but sits on one dense line, the <a href=\"https:\/\/html-editor-online.com\/tools\/json_formatter\" title=\"JSON Formatter\">JSON Formatter<\/a> pretty-prints it with indentation so field names and nesting are easy to read. Formatting changes presentation only. It does not change which schema rules the data satisfies, so a formatted file can still fail validation.<\/p>\n\n\n<div class=\"wp-block-image heo-auto-image\">\n<figure data-wp-context=\"{&quot;imageId&quot;:&quot;6b0893c38b19f&quot;}\" data-wp-interactive=\"core\/image\" data-wp-key=\"6b0893c38b19f\" class=\"aligncenter size-large wp-lightbox-container\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"576\" data-wp-class--hide=\"state.isContentHidden\" data-wp-class--show=\"state.isContentVisible\" data-wp-init=\"callbacks.setButtonStyles\" data-wp-on--click=\"actions.showLightbox\" data-wp-on--load=\"callbacks.setButtonStyles\" data-wp-on--pointerdown=\"actions.preloadImage\" data-wp-on--pointerenter=\"actions.preloadImageWithDelay\" data-wp-on--pointerleave=\"actions.cancelPreload\" data-wp-on-window--resize=\"callbacks.setButtonStyles\" src=\"https:\/\/html-editor-online.com\/blog\/wp-content\/uploads\/2026\/11\/json-schema-validator-python-image-3-879-3-a3efb903f9af57dd-1024x576.jpg\" alt=\"Illustration of a template card compared with a data card to represent a schema and sample data\" class=\"wp-image-928\" srcset=\"https:\/\/html-editor-online.com\/blog\/wp-content\/uploads\/2026\/11\/json-schema-validator-python-image-3-879-3-a3efb903f9af57dd-1024x576.jpg 1024w, https:\/\/html-editor-online.com\/blog\/wp-content\/uploads\/2026\/11\/json-schema-validator-python-image-3-879-3-a3efb903f9af57dd-300x169.jpg 300w, https:\/\/html-editor-online.com\/blog\/wp-content\/uploads\/2026\/11\/json-schema-validator-python-image-3-879-3-a3efb903f9af57dd-768x432.jpg 768w, https:\/\/html-editor-online.com\/blog\/wp-content\/uploads\/2026\/11\/json-schema-validator-python-image-3-879-3-a3efb903f9af57dd.jpg 1200w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><button\n\t\t\tclass=\"lightbox-trigger\"\n\t\t\ttype=\"button\"\n\t\t\taria-haspopup=\"dialog\"\n\t\t\tdata-wp-bind--aria-label=\"state.thisImage.triggerButtonAriaLabel\"\n\t\t\tdata-wp-init=\"callbacks.initTriggerButton\"\n\t\t\tdata-wp-on--click=\"actions.showLightbox\"\n\t\t\tdata-wp-style--right=\"state.thisImage.buttonRight\"\n\t\t\tdata-wp-style--top=\"state.thisImage.buttonTop\"\n\t\t>\n\t\t\t<svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" width=\"12\" height=\"12\" fill=\"none\" viewBox=\"0 0 12 12\">\n\t\t\t\t<path fill=\"#fff\" d=\"M2 0a2 2 0 0 0-2 2v2h1.5V2a.5.5 0 0 1 .5-.5h2V0H2Zm2 10.5H2a.5.5 0 0 1-.5-.5V8H0v2a2 2 0 0 0 2 2h2v-1.5ZM8 12v-1.5h2a.5.5 0 0 0 .5-.5V8H12v2a2 2 0 0 1-2 2H8Zm2-12a2 2 0 0 1 2 2v2h-1.5V2a.5.5 0 0 0-.5-.5H8V0h2Z\" \/>\n\t\t\t<\/svg>\n\t\t<\/button><\/figure>\n<\/div>\n\n\n<h2 class=\"wp-block-heading\" id=\"a-small-schema-and-two-data-files-to-test-with-3\">A small schema and two data files to test with<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Save this as <code>schema.json<\/code>. It uses Draft 2020-12 and describes an object with three fields.<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"json\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">{\n  &quot;$schema&quot;: &quot;https:\/\/json-schema.org\/draft\/2020-12\/schema&quot;,\n  &quot;type&quot;: &quot;object&quot;,\n  &quot;properties&quot;: {\n    &quot;name&quot;: { &quot;type&quot;: &quot;string&quot; },\n    &quot;age&quot;: { &quot;type&quot;: &quot;integer&quot; },\n    &quot;status&quot;: { &quot;type&quot;: &quot;string&quot;, &quot;enum&quot;: &#091;&quot;active&quot;, &quot;inactive&quot;&#093; }\n  },\n  &quot;required&quot;: &#091;&quot;name&quot;, &quot;age&quot;, &quot;status&quot;&#093;\n}<\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Save this valid example as <code>data.json<\/code>.<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"json\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">{&quot;name&quot;: &quot;Ada&quot;, &quot;age&quot;: 32, &quot;status&quot;: &quot;active&quot;}<\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Then save a second file, <code>bad.json<\/code>. It is perfectly good JSON syntax, but it breaks three rules.<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"json\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">{&quot;age&quot;: &quot;32&quot;, &quot;status&quot;: &quot;pending&quot;}<\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Here <code>name<\/code> is missing, <code>age<\/code> is a string instead of an integer, and <code>status<\/code> is outside the enum. Two details are easy to miss. Listing a field under <code>properties<\/code> does not make it mandatory; only <code>required<\/code> does. And extra properties are allowed by default unless the schema restricts them, for example with <code>additionalProperties<\/code> set to <code>false<\/code>, as described in the <a href=\"https:\/\/json-schema.org\/understanding-json-schema\/reference\/object?highlight=additionalproperties\" title=\"JSON Schema - object\" target=\"_blank\" rel=\"noopener\">object keyword reference<\/a>.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"a-json-schema-validator-in-python-the-full-script-4\">A JSON schema validator in Python: the full script<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Install the package with pip. The stable documentation I checked on November 21, 2026 lists version 4.26.0 and this install command, so see the <a href=\"https:\/\/python-jsonschema.readthedocs.io\/en\/stable\/\" title=\"jsonschema 4.26.0 documentation\" target=\"_blank\" rel=\"noopener\">jsonschema documentation<\/a> for current details.<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"shell\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">pip install jsonschema<\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Save the script as <code>validate.py<\/code> in the same folder as your JSON files.<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">import json\nimport sys\nfrom jsonschema import Draft202012Validator\nfrom jsonschema.exceptions import SchemaError\n\ndata_file = sys.argv&#091;1&#093; if len(sys.argv) &gt; 1 else &#039;data.json&#039;\n\ntry:\n    with open(&#039;schema.json&#039;, encoding=&#039;utf-8&#039;) as file:\n        schema = json.load(file)\n    with open(data_file, encoding=&#039;utf-8&#039;) as file:\n        data = json.load(file)\nexcept json.JSONDecodeError as error:\n    raise SystemExit(f&#039;JSON syntax error at line {error.lineno}, column {error.colno}: {error.msg}&#039;)\nexcept OSError as error:\n    raise SystemExit(f&#039;Cannot read file: {error}&#039;)\n\ntry:\n    Draft202012Validator.check_schema(schema)\nexcept SchemaError as error:\n    raise SystemExit(f&#039;Invalid schema: {error.message}&#039;)\n\nvalidator = Draft202012Validator(schema)\nerrors = sorted(\n    validator.iter_errors(data),\n    key=lambda error: (tuple(map(str, error.path)), error.message),\n)\n\nif errors:\n    for error in errors:\n        location = &#039;.&#039;.join(map(str, error.path)) or &#039;(root)&#039;\n        print(f&#039;{location} &#091;{error.validator}&#093;: {error.message}&#039;)\n    raise SystemExit(1)\n\nprint(&#039;Data matches the schema&#039;)<\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">The script works in three stages, and each stage fails with its own message. <code>json.load()<\/code> parses a file and raises <code>json.JSONDecodeError<\/code> on a decoding failure, with <code>lineno<\/code>, <code>colno<\/code> and <code>msg<\/code> attributes. That is your syntax stage. <code>check_schema()<\/code> confirms the schema is itself a valid schema, so a typo in the schema is reported as a schema problem instead of a confusing data error. <code>iter_errors()<\/code> then yields every violation rather than stopping at the first, which lets you fix several problems per run.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"read-the-errors-and-decide-what-to-fix-first-5\">Read the errors and decide what to fix first<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Run the script on both files.<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"shell\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">python validate.py data.json\npython validate.py bad.json<\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">The valid file prints the success line. The bad file exits with status 1 and prints one line per violation. The output looks roughly like this, though exact wording and ordering can differ between library versions, so do not build logic around the message text.<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">(root) &#091;required&#093;: &#039;name&#039; is a required property\nage &#091;type&#093;: &#039;32&#039; is not of type &#039;integer&#039;\nstatus &#091;enum&#093;: &#039;pending&#039; is not one of &#091;&#039;active&#039;, &#039;inactive&#039;&#093;<\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Each line has three parts. <code>error.path<\/code> is the location inside the data, <code>error.validator<\/code> names the failed keyword and <code>error.message<\/code> describes the problem. A missing required property is reported against the containing object, so its path is empty, which the script prints as <code>(root)<\/code>.<\/p>\n\n\n\n<figure class=\"wp-block-table\"><table class=\"has-fixed-layout\"><thead><tr><th>Keyword<\/th><th>What it means<\/th><th>Usual fix<\/th><\/tr><\/thead><tbody><tr><td><code>required<\/code><\/td><td>A mandatory property is absent<\/td><td>Add the field in the data, or the producer&#8217;s output<\/td><\/tr><tr><td><code>type<\/code><\/td><td>A value has the wrong JSON type<\/td><td>Send a number, not a quoted string<\/td><\/tr><tr><td><code>enum<\/code><\/td><td>The value is not in the allowed list<\/td><td>Use an allowed value, or update the schema deliberately<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\">Work in this order:<\/p>\n\n\n\n<ol class=\"wp-block-list\">\n<li>Resolve any JSON syntax error reported by <code>json.load()<\/code> or by the syntax tools.<\/li>\n\n\n\n<li>Fix an <code>Invalid schema<\/code> message, because data results mean nothing against a broken schema.<\/li>\n\n\n\n<li>Address missing required fields, then wrong types, then disallowed enum values.<\/li>\n\n\n\n<li>Rerun the script until it prints the success line.<\/li>\n\n\n<\/ol>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"limits-to-keep-in-mind-before-you-trust-a-pass-6\">Limits to keep in mind before you trust a pass<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">A passing run proves less than it seems. Python&#8217;s standard decoder accepts some nonstandard values, including <code>NaN<\/code>, by default, so a successful <code>json.load()<\/code> does not guarantee strict JSON syntax. That is why the earlier strict browser-based check is still worth doing. The <code>json<\/code> module also documents a <code>parse_constant<\/code> hook if you want to reject those values in code.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Remember what each tool covers. The online syntax tools do not perform schema validation, and the Python script does not tell you whether values are semantically right. An age of 3 passes an integer check even if the real person is 30. Add rules such as <code>minimum<\/code> or <code>additionalProperties<\/code> when you need them.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Large numbers deserve a special note. The browser&#8217;s <code>JSON.parse<\/code> can round long integers, so a normalized copy from a browser tool may differ from your source. Read the write-up on <a href=\"https:\/\/html-editor-online.com\/blog\/json-validator-changes-large-integer-id\/\" title=\"JSON Validator Changes Large Integer Id\">large integer IDs changing after validation<\/a>, and keep long identifiers as strings in your schema and data.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">For more habits that make files easier to review, see these <a href=\"https:\/\/html-editor-online.com\/blog\/tips-for-formatting-json\/\" title=\"5 Must-Know Tips for Formatting JSON Like a Pro\">tips for formatting JSON<\/a>, and the <a href=\"https:\/\/html-editor-online.com\/blog\/online-json-editor-guide\/\" title=\"Online JSON Editor Guide\">guide to editing JSON in the browser<\/a> if you work with larger files.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"frequently-asked-questions\">Frequently asked questions<\/h2>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"faq-1\">How do I validate JSON against a schema in Python?<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">Install the jsonschema package, load the schema and the data with json.load(), call Draft202012Validator.check_schema() on the schema, then loop over validator.iter_errors(data). If the list is empty, the data matches the schema. The script in this article does exactly that.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"faq-2\">What is the difference between JSON syntax validation and JSON Schema validation?<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">Syntax validation asks whether text can be parsed as JSON at all. Schema validation asks whether the parsed data follows rules such as required properties, types and allowed values. A file can pass the first and fail the second, and the first has to succeed before the second can run.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"faq-3\">Does the online JSON Validator check against a JSON Schema?<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">No. The JSON Validator checks syntax with the browser&#8217;s JSON.parse and returns a normalized copy. The JSON Editor also validates syntax only and has no JSON Schema validation. Use the Python script for structure rules.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"faq-4\">Does JSON Schema validate Python data or only JSON text?<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">The jsonschema library validates the parsed Python object, such as a dict or list, not the raw text. That is why json.load() runs first. If parsing fails, you get a JSONDecodeError and no schema checks happen.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"faq-5\">Why does my data pass when a field is listed under properties?<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">Listing a field under properties only describes what the field should look like if it is present. It does not make the field mandatory. Add the field name to the required array to make a missing field an error.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"faq-6\">Are extra properties allowed by default?<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">Yes. Unless the schema restricts them, for example with additionalProperties set to false, an object can contain fields the schema never mentions. This means a misspelled field name can slip through, so add that restriction when you want strict objects.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"faq-7\">Can JSON Repair or the JSON Formatter fix schema violations?<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">No. JSON Repair addresses common formatting mistakes and can change values, so review its output. The JSON Formatter only indents parseable data. A missing field, wrong type or disallowed enum value has to be corrected in the data or its producer, then validated again.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"next-steps\">Next steps<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">A reliable json schema validator in Python workflow has a clear order: confirm the text is well-formed, make sure the schema is valid, then read each violation by location and keyword. Save the sample files, run the script on both, then break one rule at a time in <code>data.json<\/code> and watch which message changes. When you adapt it, replace the sample schema with your own and keep a strict syntax check as the first step.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Related tools and resources on HTML Editor Online:<\/strong><\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><a href=\"https:\/\/html-editor-online.com\/tools\/json_validator\">JSON Validator<\/a><\/li>\n\n\n\n<li><a href=\"https:\/\/html-editor-online.com\/editors\/json\">JSON Editor<\/a><\/li>\n\n\n\n<li><a href=\"https:\/\/html-editor-online.com\/tools\/json_formatter\">JSON Formatter<\/a><\/li>\n\n\n\n<li><a href=\"https:\/\/html-editor-online.com\/tools\/json_repair\">JSON Repair<\/a><\/li>\n\n\n\n<li><a href=\"https:\/\/html-editor-online.com\/blog\/json-validator-changes-large-integer-id\/\">JSON Validator Changes Large Integer Id<\/a><\/li>\n\n\n<\/ul>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"sources\">Sources and further reading<\/h2>\n\n\n\n<ul class=\"wp-block-list\">\n<li><a href=\"https:\/\/html-editor-online.com\/tools\/json_validator\">JSON Validator<\/a><\/li>\n\n\n\n<li><a href=\"https:\/\/json-schema.org\/learn\/getting-started-step-by-step\" target=\"_blank\" rel=\"noopener\">Creating your first schema<\/a><\/li>\n\n\n\n<li><a href=\"https:\/\/html-editor-online.com\/editors\/json\">JSON Editor<\/a><\/li>\n\n\n\n<li><a href=\"https:\/\/html-editor-online.com\/tools\/json_formatter\">JSON Formatter<\/a><\/li>\n\n\n\n<li><a href=\"https:\/\/html-editor-online.com\/tools\/json_repair\">JSON Repair<\/a><\/li>\n\n\n\n<li><a href=\"https:\/\/json-schema.org\/understanding-json-schema\/reference\/object?highlight=additionalproperties\" target=\"_blank\" rel=\"noopener\">JSON Schema &#8211; object<\/a><\/li>\n\n\n\n<li><a href=\"https:\/\/json-schema.org\/understanding-json-schema\/reference\/type\" target=\"_blank\" rel=\"noopener\">JSON Schema &#8211; Type-specific Keywords<\/a><\/li>\n\n\n\n<li><a href=\"https:\/\/www.rfc-editor.org\/info\/rfc8259\/\" target=\"_blank\" rel=\"noopener\">RFC 8259: The JavaScript Object Notation (JSON) Data Interchange Format | RFC Editor<\/a><\/li>\n\n\n\n<li><a href=\"https:\/\/python-jsonschema.readthedocs.io\/en\/stable\/\" target=\"_blank\" rel=\"noopener\">jsonschema 4.26.0 documentation<\/a><\/li>\n\n\n<\/ul>\n\n\n","protected":false},"excerpt":{"rendered":"<p>A json schema validator in Python checks structure, not syntax. Learn the order: parse JSON, check the schema, then read each error.<\/p>\n","protected":false},"author":1,"featured_media":922,"comment_status":"closed","ping_status":"","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[27],"tags":[302,299,301,53,300,28],"class_list":["post-921","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-json-tools","tag-draft-2020-12","tag-json-schema","tag-json-syntax","tag-json-validation","tag-jsonschema-library","tag-python"],"_links":{"self":[{"href":"https:\/\/html-editor-online.com\/blog\/wp-json\/wp\/v2\/posts\/921","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/html-editor-online.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/html-editor-online.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/html-editor-online.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/html-editor-online.com\/blog\/wp-json\/wp\/v2\/comments?post=921"}],"version-history":[{"count":4,"href":"https:\/\/html-editor-online.com\/blog\/wp-json\/wp\/v2\/posts\/921\/revisions"}],"predecessor-version":[{"id":929,"href":"https:\/\/html-editor-online.com\/blog\/wp-json\/wp\/v2\/posts\/921\/revisions\/929"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/html-editor-online.com\/blog\/wp-json\/wp\/v2\/media\/922"}],"wp:attachment":[{"href":"https:\/\/html-editor-online.com\/blog\/wp-json\/wp\/v2\/media?parent=921"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/html-editor-online.com\/blog\/wp-json\/wp\/v2\/categories?post=921"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/html-editor-online.com\/blog\/wp-json\/wp\/v2\/tags?post=921"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}