Bird
0
0

You want to send a request body with optional fields. How should you structure the JSON to omit a field if it has no value?

hard📝 Application Q9 of 15
Rest API - Request and Response Format
You want to send a request body with optional fields. How should you structure the JSON to omit a field if it has no value?
ASet the field value to null
BSimply exclude the field from the JSON object
CSet the field value to an empty string ""
DInclude the field with value 0
Step-by-Step Solution
Solution:
  1. Step 1: Understand optional fields in JSON

    Omitting a field means not including it at all in the JSON object.
  2. Step 2: Differentiate from null or empty values

    Null or empty string means the field exists but has no value; 0 is a numeric value.
  3. Final Answer:

    Simply exclude the field from the JSON object -> Option B
  4. Quick Check:

    Omit optional fields by excluding them [OK]
Quick Trick: Leave out optional fields to omit them [OK]
Common Mistakes:
  • Sending null instead of omitting
  • Using empty strings for missing data
  • Including zero when not applicable

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Rest API Quizzes