JSON MCQs – JSON Schema

11.) What is the use of the $ref keyword in JSON Schema?

A) To reference external files
B) To include reusable schema definitions
C) To define a default value
D) To specify required properties

Answer: Option B

Explanation: The $ref keyword allows referencing reusable schema definitions within a JSON Schema.

12.) What is the difference between allOf and oneOf in JSON Schema?

A) allOf validates all schemas, oneOf validates only one schema
B) allOf is for strings, oneOf is for arrays
C) oneOf requires at least one match, allOf requires none
D) allOf allows duplicates, oneOf does not

Answer: Option A

Explanation: allOf ensures the data matches all the provided schemas, while oneOf ensures it matches exactly one schema.

13.) How do you specify a pattern for a string in JSON Schema?

A) match
B) regex
C) pattern
D) format

Answer: Option C

Explanation: The pattern keyword is used to define a regular expression that the string must match.

14.) What does the type keyword accept for mixed data types?

A) A single string
B) An array of types
C) A numeric range
D) A boolean flag

Answer: Option B

Explanation: To allow multiple types, the type keyword accepts an array of types, such as [“string”, “number”].

15.) Which keyword restricts the number of items in a JSON array?

A) minLength
B) maxItems
C) maxSize
D) arrayLimit

Answer: Option B

Explanation: The maxItems keyword defines the maximum number of elements allowed in an array.

16.) What is the purpose of the dependencies keyword in JSON Schema?

A) To define key dependencies
B) To validate nested objects
C) To specify default values
D) To define type constraints

Answer: Option A

Explanation: The dependencies keyword specifies keys that are required if another key is present.

17.) What is the default value of additionalProperties in JSON Schema?

A) false
B) true
C) undefined
D) null

Answer: Option B

Explanation: By default, additionalProperties is set to true, allowing extra fields unless explicitly restricted.

18.) How do you validate that a JSON object has no additional fields?

A) additionalProperties: false
B) maxProperties: 0
C) properties: []
D) additionalFields: false

Answer: Option A

Explanation: Setting additionalProperties to false ensures no extra fields are allowed in the object.

19.) How do you specify a format for email validation in JSON Schema?

A) type: “email”
B) pattern: “/[email]/”
C) format: “email”
D) validate: “email”

Answer: Option C

Explanation: The format keyword is used to specify predefined formats like email or date.

20.) What does the title keyword do in JSON Schema?

A) Sets a required field
B) Provides a description of the schema
C) Gives a short label to the schema or property
D) Specifies a string pattern

Answer: Option C

Explanation: The title keyword provides a short, descriptive label for a schema or property.

Leave a Reply

Your email address will not be published. Required fields are marked *