0
0
Rest APIprogramming~20 mins

Schema definitions in Rest API - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Schema Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
Predict Output
intermediate
2:00remaining
What is the output of this JSON schema validation?
Given this JSON schema and data, what will be the validation result?
Rest API
{
  "$schema": "http://json-schema.org/draft-07/schema#",
  "type": "object",
  "properties": {
    "name": {"type": "string"},
    "age": {"type": "integer", "minimum": 0}
  },
  "required": ["name", "age"]
}

Data:
{
  "name": "Alice",
  "age": -5
}
AInvalid: age is less than minimum 0
BValid
CInvalid: name is missing
DInvalid: age is not an integer
Attempts:
2 left
💡 Hint
Check the 'minimum' constraint for the 'age' property.
🧠 Conceptual
intermediate
1:30remaining
Which JSON schema keyword restricts the allowed properties in an object?
In JSON schema, which keyword limits the properties that can appear in an object to only those specified?
A"required"
B"additionalProperties"
C"properties"
D"patternProperties"
Attempts:
2 left
💡 Hint
It controls whether extra properties beyond those listed are allowed.
🔧 Debug
advanced
2:00remaining
Identify the error in this JSON schema snippet
What is wrong with this JSON schema snippet that defines an array?
Rest API
{
  "type": "array",
  "items": {
    "type": "string"
  },
  "minItems": "2"
}
A"minItems" should be a number, not a string
B"items" must be an array, not an object
C"type" must be "object" for arrays
D"minItems" is not a valid keyword
Attempts:
2 left
💡 Hint
Check the data type of the value for 'minItems'.
📝 Syntax
advanced
2:00remaining
Which option correctly defines a schema for a nullable string?
You want a property that can be either a string or null. Which JSON schema snippet is correct?
A{ "anyOf": ["string", "null"] }
B{ "type": "string|null" }
C{ "type": "string", "nullable": true }
D{ "type": ["string", "null"] }
Attempts:
2 left
💡 Hint
The 'type' keyword can accept an array of types.
🚀 Application
expert
2:30remaining
How many properties will be valid with this schema?
Given this schema, how many properties can a valid object have?
Rest API
{
  "type": "object",
  "properties": {
    "a": {"type": "string"},
    "b": {"type": "number"}
  },
  "additionalProperties": false
}
AAt least 2 properties required
BAny number of properties allowed
COnly 2 properties: 'a' and 'b'
DExactly 1 property allowed
Attempts:
2 left
💡 Hint
Check the effect of 'additionalProperties': false.