JSON MCQs – JSON Schema

JSON Schema is a powerful tool used to define and validate the structure of JSON data. Mastering JSON Schema concepts is critical for developers preparing for interviews, as it demonstrates proficiency in designing and validating JSON data structures. The following MCQs are curated to help you understand JSON Schema basics, advanced concepts, and practical usage.

1.) What is JSON Schema?

A) A format to store JSON data
B) A method to minify JSON files
C) A library to parse JSON data
D) A specification to define and validate the structure of JSON data

Answer: Option D

Explanation: JSON Schema is a specification used to define the structure, format, and constraints of JSON data for validation purposes.

2.) Which keyword in JSON Schema defines the type of a value?

A) format
B) type
C) properties
D) items

Answer: Option B

Explanation: The type keyword is used to specify the data type of a value in JSON Schema, such as string, number, or object.

3.) What does the properties keyword do in JSON Schema?

A) Defines the keys allowed in an object
B) Specifies the data type of an array
C) Lists all required fields in an object
D) Defines the maximum number of keys in an object

Answer: Option A

Explanation: The properties keyword in JSON Schema is used to define the allowed keys and their corresponding constraints in an object.

4.) Which keyword is used to specify required fields in a JSON object?

A) mandatory
B) required
C) fields
D) include

Answer: Option B

Explanation: The required keyword in JSON Schema lists the keys that must be present in a JSON object.

5.) What does the enum keyword specify in JSON Schema?

A) The default value of a property
B) The format of a date field
C) The maximum length of a string
D) A list of allowed values for a property

Answer: Option D

Explanation: The enum keyword restricts a property to a predefined set of allowed values.

6.) How do you specify that a JSON object must have at least one key in JSON Schema?

A) minItems: 1
B) minProperties: 1
C) minKeys: 1
D) required: true

Answer: Option B

Explanation: The minProperties keyword is used to enforce a minimum number of keys in a JSON object.

7.) Which keyword specifies the schema for items in a JSON array?

A) properties
B) type
C) items
D) definitions

Answer: Option C

Explanation: The items keyword is used to define the schema for elements in a JSON array.

8.) What is the purpose of the additionalProperties keyword?

A) To define extra fields that are allowed in an object
B) To validate nested objects
C) To specify array constraints
D) To allow duplicate keys in an object

Answer: Option A

Explanation: The additionalProperties keyword specifies whether extra keys not defined in properties are allowed in a JSON object.

9.) What does the oneOf keyword do in JSON Schema?

A) Validates against one specific type
B) Requires all listed schemas to match
C) Combines multiple schemas
D) Ensures that the data matches exactly one of the specified schemas

Answer: Option D

Explanation: The oneOf keyword ensures that data matches exactly one of the schemas listed.

10.) Which keyword defines a numeric range in JSON Schema?

A) min and max
B) minimum and maximum
C) range
D) numberRange

Answer: Option B

Explanation: The minimum and maximum keywords specify the range of numeric values allowed in a JSON field.

Leave a Reply

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