Your country

Tools that support it use your country for local currency, number formats, units and paper size. Your choice is saved only in this browser.

Type a name or a two-letter code. Use the up and down arrow keys to move through the countries, Enter to choose one and Escape to close.

Data Formats (JSON, YAML, TOML, XML, CSV) Module 3

JSON Schema 2020-12 interview questions

Interview questions on JSON Schema 2020-12: short warm-ups, then what each harder question tests, the first step of a good answer and its follow-ups.

18 questions: 6 warm-ups and 12 with model answers · Levels: Fresher to senior

Warm-up questions

Short questions with short answers, each answered in full.

  1. Fresher to mid

    Does "type": "integer" accept the value 1.0 in JSON Schema 2020-12?

    Answered in the lesson Your first JSON Schema 2020-12

  2. Fresher to mid

    How do prefixItems and items divide an array between them in JSON Schema 2020-12?

    prefixItems is an array of schemas, one per position, for tuples: the first element must pass the first schema, the second the second, and so on. items is a single schema for every element after those positions, or for every element when there is no prefixItems. prefixItems does not require the positions to exist, so a fixed-length tuple also needs minItems, and "items": false refuses any element after them. Draft-07 wrote positions as an array under items and the rest under additionalItems; 2020-12 renamed both.

    From the lesson Objects and arrays in JSON Schema

  3. Fresher to mid

    When does oneOf refuse a value that anyOf accepts?

    Answered in the lesson Composition and conditionals in JSON Schema

  4. Mid

    What does "$ref": "#/$defs/address" mean, and how is "#address" different?

    Answered in the lesson JSON Schema $ref, $defs, $id and $dynamicRef

  5. Fresher to mid

    Why does {"format": "email"} accept "not-an-email" in a validator that follows 2020-12?

    Answered in the lesson JSON Schema formats, vocabularies and validators

  6. Mid

    How do you write OpenAPI 3.0's "type": "string", "nullable": true in OpenAPI 3.1?

    Answered in the lesson Drafts, OpenAPI and code from JSON Schema

Questions with model answers

What each question tests, the first step of a good answer and the follow-ups to expect.

  1. Fresher to mid

    Your team generated a JSON Schema from a month of API responses and checks every response against it in CI. A response with "status": "refundd" and a total of -500 paise passed. Why did the schema let it through, and how would you tighten it without failing good responses?

    What it tests
    Knowing what a schema inferred from samples can and cannot know, turning codes into enums and amounts into bounded integers, and rolling out a stricter schema against real traffic.
    First step
    Read the generated subschemas for status and total. They will say "type": "string" and "type": "integer" and nothing more, because a sample shows the type of a value, never the rule behind it. Every allowed status and every bound has to be added by someone who knows the data.
    Follow-ups

    From the lesson Your first JSON Schema 2020-12

    Model answer, Pro. Model answers open with any pass; prices are in the notice on this page.

    Opening the model answers with your pass…

    Model answers open with any MySmartCoPilot pass.

    • Pro pass · 1 week₹79$2.99
    • 30 days₹179$5.99
    • 1 year₹1,699$45

    One payment; a pass never renews. The price shown is the total you pay: no fees or charges are added at checkout.

    It also opens every other in-depth part in Learn and every Pro tool. Sales are final, except where the law gives you a right to withdraw, for example in the EU and the UK (refund policy).

    In the answer:

    • Model answer
    • Follow-up answers
    • Common mistakes
    • Rubric
    • Variants
    • about 3 minutes
  2. Mid to senior

    A Python service and a Node.js service share a JSON Schema whose product code rule is the pattern ^[A-Z]{2}\d{4}$. The Python service accepts two codes that the Node.js service refuses. What could the two codes be, and how do you make the services agree?

    What it tests
    Knowing that pattern uses the ECMA-262 dialect, how Python's re reads $ and \d differently, and how to write patterns, length bounds and tests that two runtimes read the same way.
    First step
    Look for the two places where Python's re and ECMA-262 read this pattern differently: in Python, $ also matches just before a final newline, and \d matches any Unicode decimal digit. A code with a trailing newline and a code written with Devanagari or Arabic-Indic digits are the likely pair.
    Follow-ups

    From the lesson Your first JSON Schema 2020-12

    Model answer, Pro.

    In the answer:

    • Model answer
    • Follow-up answers
    • Common mistakes
    • Rubric
    • Variants
    • about 3 minutes
  3. Mid to senior

    After a refactor, a request schema became an allOf of a shared base schema plus its own properties, closed with "additionalProperties": false. Every valid request is now refused with "property is not allowed" errors. Explain the cause and the fix, and what you would do for a service whose validator supports only draft-07.

    What it tests
    Knowing that additionalProperties sees only the properties beside it, that unevaluatedProperties sees through applicators, and how to close a composed schema where 2019-09 keywords are missing.
    First step
    Read which members the errors name: they are the ones the base schema names inside allOf. additionalProperties judges members only against properties and patternProperties in its own schema object, so every member of the base looks unknown to it.
    Follow-ups

    From the lesson Objects and arrays in JSON Schema

    Model answer, Pro.

    In the answer:

    • Model answer
    • Follow-up answers
    • Common mistakes
    • Rubric
    • Variants
    • about 3 minutes
  4. Fresher to mid

    An invoice may have a tax_id. When it does, company_name and billing_address must be present, and billing_address must include a postcode. Without a tax_id, both may still appear. Which JSON Schema 2020-12 keywords express this, and which mistakes would your tests look for?

    What it tests
    Using dependentRequired and dependentSchemas for rules that start from a member's presence, their one-way nature, nested requirements, and test documents for each direction.
    First step
    Separate the two kinds of rule. "company_name must be present" is a list of names, so it is dependentRequired. "billing_address must include a postcode" is a rule about another member's value, so it needs a schema, under dependentSchemas.
    Follow-ups

    From the lesson Objects and arrays in JSON Schema

    Model answer, Pro.

    In the answer:

    • Model answer
    • Follow-up answers
    • Common mistakes
    • Rubric
    • Variants
    • about 2 minutes
  5. Mid to senior

    Customers see five or six error messages when they get one payment field wrong at checkout. The payment schema is a oneOf of three shapes, each with a const on the method tag. Why so many messages, and how would you change the schema so that each mistake gives one message at the right field?

    What it tests
    Knowing how a failed oneOf is reported, rewriting a tagged union as an if chain on the tag, and keeping the rules of the data apart from how errors are shown.
    First step
    Read the keyword locations of the errors: one is /oneOf itself and the rest come from /oneOf/0, /oneOf/1 and /oneOf/2. A failed oneOf reports why every branch failed, including the branches for payment methods the customer never chose.
    Follow-ups

    From the lesson Composition and conditionals in JSON Schema

    Model answer, Pro.

    In the answer:

    • Model answer
    • Follow-up answers
    • Common mistakes
    • Rubric
    • Variants
    • about 3 minutes
  6. Fresher to mid

    An order needs a tax_id when buyer_type is "business", and must not have one when it is "personal". The first version of the schema tells orders that leave out buyer_type that they need a tax_id. Why, and how would you write the rule?

    What it tests
    Writing if, then and else for a rule that depends on a value, guarding the if with required, and saying "must not have" with a schema.
    First step
    Look at what the if tests. If it checks buyer_type with properties alone, it passes for an order without buyer_type, because properties checks only the members that are there, so then runs and demands the tax_id.
    Follow-ups

    From the lesson Composition and conditionals in JSON Schema

    Model answer, Pro.

    In the answer:

    • Model answer
    • Follow-up answers
    • Common mistakes
    • Rubric
    • Variants
    • about 3 minutes
  7. Mid to senior

    A service validates partners' uploads against schemas that the partners also upload, and its validator fetches every $ref URL it meets. What can go wrong, and how would you redesign the way schemas are loaded?

    What it tests
    Recognising request forgery through $ref, knowing that schema URIs are identifiers, and designing a registry of known schemas, bundles and a refusal for anything else.
    First step
    Treat every $ref as an outbound request chosen by an outsider: a partner's schema can name an address on the service's own network, or a huge file, and the validator will request it. The specification itself says a schema's URI does not mean anything should be downloaded.
    Follow-ups

    From the lesson JSON Schema $ref, $defs, $id and $dynamicRef

    Model answer, Pro.

    In the answer:

    • Model answer
    • Follow-up answers
    • Common mistakes
    • Rubric
    • Variants
    • about 3 minutes
  8. Mid to senior

    A schema works in your repository, where each file is loaded from its path. A colleague copies every file into one document under $defs, and references start failing with "no schema" errors. What went wrong, and how do you bundle the files correctly?

    What it tests
    Knowing how $id sets base URIs, why embedded resources need absolute $id values, and how the specification's bundling keeps every reference unchanged.
    First step
    Check the $id of each copied file. Files loaded from a path took their base URI from where they were found; copies without an $id, or with a relative one, now resolve against the root document's URI, so their references name files that nothing has registered.
    Follow-ups

    From the lesson JSON Schema $ref, $defs, $id and $dynamicRef

    Model answer, Pro.

    In the answer:

    • Model answer
    • Follow-up answers
    • Common mistakes
    • Rubric
    • Variants
    • about 3 minutes
  9. Mid to senior

    A Python service accepts an order timestamp that a Node.js service refuses, although both use the same schema with "format": "date-time". What could cause the difference, and how would you make the two services agree?

    What it tests
    Knowing that format asserts only by option or by dialect, that implementations check formats differently, and how to pin the behaviour and test it in both services.
    First step
    Check whether each service asserts formats at all. In the default 2020-12 dialect format is only an annotation, so a validator never told to check formats accepts every string. Then check how each implements date-time, because some checks depend on optional packages.
    Follow-ups

    From the lesson JSON Schema formats, vocabularies and validators

    Model answer, Pro.

    In the answer:

    • Model answer
    • Follow-up answers
    • Common mistakes
    • Rubric
    • Variants
    • about 3 minutes
  10. Fresher to mid

    A schema change added "maxLenght": 120 to a gift note, and it shipped. Weeks later a note of 5,000 characters broke the label printer. Why did no test catch it, and what would you add to the pipeline?

    What it tests
    Knowing that unknown keywords are annotations, catching typos with strict compilation or a keyword check, and testing schemas with documents that must fail.
    First step
    Look at the keyword: maxLenght is not a 2020-12 keyword, so a validator that follows the specification treats it as an annotation and checks nothing. Every test with a valid note passed, because the rule never existed.
    Follow-ups

    From the lesson JSON Schema formats, vocabularies and validators

    Model answer, Pro.

    In the answer:

    • Model answer
    • Follow-up answers
    • Common mistakes
    • Rubric
    • Variants
    • about 3 minutes
  11. Mid to senior

    Your team migrated 40 draft-07 schemas to 2020-12 with a script that renames keywords, and some valid requests are now refused. What did the script most likely miss, and how would you prove a migration safe before it ships?

    What it tests
    Knowing the changes that alter results without errors, especially keywords beside $ref, and proving a migration by running a test set under both drafts' rules.
    First step
    Look for keywords beside a $ref in the old schemas. Draft-07 ignored them, and 2020-12 applies them, so a rename that kept them added rules nobody had ever run; in the lesson's order schema, one such maxLength changed 8 of 108 results.
    Follow-ups

    From the lesson Drafts, OpenAPI and code from JSON Schema

    Model answer, Pro.

    In the answer:

    • Model answer
    • Follow-up answers
    • Common mistakes
    • Rubric
    • Variants
    • about 3 minutes
  12. Mid to senior

    Front-end types are generated from an API's JSON Schema, and the server validates with the same schema. A release adds a pattern to the order id and a minimum to the quantity, and the generated types do not change at all. Is that a bug, and how do you keep schema, types and validation in step?

    What it tests
    Knowing what generated types can and cannot hold, keeping the schema as the source of truth, and wiring generation and validation into the build.
    First step
    Check what the generator can express: TypeScript has no integer type and the generated types hold no pattern or minimum, so an unchanged type is expected. The rules still apply where the schema validates, at run time.
    Follow-ups

    From the lesson Drafts, OpenAPI and code from JSON Schema

    Model answer, Pro.

    In the answer:

    • Model answer
    • Follow-up answers
    • Common mistakes
    • Rubric
    • Variants
    • about 3 minutes

All Data Formats (JSON, YAML, TOML, XML, CSV) interview questions · The Data Formats (JSON, YAML, TOML, XML, CSV) track

Quick answers and tool search

Type to search tools or to get a quick answer, for example 18% of 2500. Use the up and down arrow keys to move through the results, Enter to choose, and Escape to close.