Bird
Raised Fist0
Postmantesting~20 mins

JSON body in Postman - Practice Problems & Coding Challenges

Choose your learning style10 modes available
Challenge - 5 Problems
🎖️
JSON Body 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 validation test?
Given this JSON body sent in a POST request, what will the test assertion result be in Postman?
Postman
{
  "user": {
    "id": 123,
    "name": "Alice",
    "roles": ["admin", "editor"]
  }
}

// Test script snippet:
pm.test("User ID is 123", () => {
  pm.expect(pm.response.json().user.id).to.eql(123);
});
ATest fails due to syntax error in JSON body
BTest fails because user.id is a string, not a number
CTest passes because user.id equals 123
DTest fails because roles array is empty
Attempts:
2 left
💡 Hint
Check the data type of user.id in the JSON body.
❓ assertion
intermediate
2:00remaining
Which assertion correctly checks if the JSON response contains a non-empty roles array?
You want to write a Postman test to verify the roles array in the JSON response is not empty. Which assertion is correct?
Apm.expect(pm.response.json().user.roles.length).to.be.above(0);
Bpm.expect(pm.response.json().user.roles).to.eql([]);
Cpm.expect(pm.response.json().user.roles).to.be.empty();
Dpm.expect(pm.response.json().user.roles).to.have.lengthOf(0);
Attempts:
2 left
💡 Hint
Think about how to check array length is greater than zero.
❓ locator
advanced
2:00remaining
Identify the correct JSON path to access the user's second role
Given this JSON body: { "user": { "id": 123, "name": "Alice", "roles": ["admin", "editor"] } } Which JSON path correctly accesses the second role?
Auser.roles[1]
Buser.roles.1
Cuser.roles(1)
Duser.roles[2]
Attempts:
2 left
💡 Hint
Remember JSON arrays are zero-indexed.
🔧 Debug
advanced
2:00remaining
Why does this Postman test fail when checking a JSON boolean value?
Test script: pm.test("Check active status", () => { pm.expect(pm.response.json().user.active).to.eql("true"); }); JSON response: { "user": { "active": true } } Why does the test fail?
AThe test syntax is invalid and causes a runtime error
BThe JSON response is missing the active field
CThe JSON boolean true is case-sensitive and must be "True"
DThe test compares boolean true to string "true", causing failure
Attempts:
2 left
💡 Hint
Check the data types compared in the assertion.
❓ framework
expert
3:00remaining
Which Postman test script correctly validates that the JSON response has a 'user' object with a 'name' property of type string?
Choose the test script that correctly checks the presence and type of 'name' inside 'user' in the JSON response.
A
pm.test("User name is string", () => {
  const jsonData = pm.response.json();
  pm.expect(jsonData.user.name).to.be.string();
});
B
pm.test("User name is string", () => {
  const jsonData = pm.response.json();
  pm.expect(jsonData.user).to.have.property('name').that.is.a('string');
});
C
pm.test("User name is string", () => {
  const jsonData = pm.response.json();
  pm.expect(jsonData.user.name).to.be.a('string');
});
D
pm.test("User name is string", () => {
  const jsonData = pm.response.json();
  pm.expect(typeof jsonData.user.name).to.eql('string');
});
Attempts:
2 left
💡 Hint
Check the chaining syntax for property and type assertions in Postman.

Practice

(1/5)
1. What is the correct way to represent a JSON body with a user's name and age in Postman?
easy
A. {"name": "Alice", "age": 30}
B. {name: Alice, age: 30}
C. {'name': 'Alice', 'age': 30}
D. {name = "Alice", age = 30}

Solution

  1. Step 1: Identify JSON syntax rules

    JSON keys and string values must be in double quotes. Numbers do not need quotes.
  2. Step 2: Check each option for correct JSON format

    {"name": "Alice", "age": 30} uses double quotes correctly around keys and string values. The other options use incorrect quotes or syntax.
  3. Final Answer:

    {"name": "Alice", "age": 30} -> Option A
  4. Quick Check:

    JSON keys and strings use double quotes = A [OK]
Hint: Always use double quotes for keys and string values in JSON [OK]
Common Mistakes:
  • Using single quotes instead of double quotes
  • Omitting quotes around keys
  • Using equal signs instead of colons
2. Which of the following is a valid JSON body to send a list of colors in Postman?
easy
A. {"colors": ("red", "green", "blue")}
B. {colors: [red, green, blue]}
C. {"colors": "red", "green", "blue"}
D. {"colors": ["red", "green", "blue"]}

Solution

  1. Step 1: Understand JSON array syntax

    Arrays in JSON are enclosed in square brackets with comma-separated values, strings in double quotes.
  2. Step 2: Validate each option's array format

    {"colors": ["red", "green", "blue"]} correctly uses square brackets and double quotes. The other options are invalid: one uses parentheses, another is missing array brackets, and one lacks quotes around strings and keys.
  3. Final Answer:

    {"colors": ["red", "green", "blue"]} -> Option D
  4. Quick Check:

    Arrays use square brackets and double quotes = B [OK]
Hint: Use square brackets for arrays and double quotes for strings [OK]
Common Mistakes:
  • Using parentheses instead of square brackets
  • Missing quotes around string values
  • Omitting brackets for arrays
3. Given this JSON body sent in Postman:
{
  "user": {
    "id": 101,
    "active": true
  },
  "roles": ["admin", "editor"]
}

What is the value of user.active?
medium
A. null
B. true
C. false
D. "true"

Solution

  1. Step 1: Locate the key user.active in the JSON

    Inside the "user" object, the key "active" has the value true without quotes, meaning boolean true.
  2. Step 2: Understand JSON boolean values

    Boolean true is a literal, not a string. So the value is the boolean true, not the string "true".
  3. Final Answer:

    true -> Option B
  4. Quick Check:

    Boolean true is unquoted true = D [OK]
Hint: Booleans in JSON are unquoted true or false [OK]
Common Mistakes:
  • Confusing boolean true with string "true"
  • Assuming missing keys have null values
  • Misreading nested object structure
4. You wrote this JSON body in Postman:
{
  "product": "Book",
  "price": 12.99,
  "inStock": yes
}

What is the error in this JSON body?
medium
A. "price" should be a string in quotes
B. "inStock" value should be true or false without quotes
C. "inStock" value 'yes' is invalid, should be true or false
D. Missing comma after "price" value

Solution

  1. Step 1: Check the value of "inStock" key

    The value 'yes' is not a valid JSON boolean or string because it lacks quotes.
  2. Step 2: Identify correct boolean values in JSON

    JSON booleans are true or false without quotes. Strings must be in double quotes. 'yes' without quotes is invalid.
  3. Final Answer:

    "inStock" value 'yes' is invalid, should be true or false -> Option C
  4. Quick Check:

    Boolean values must be true/false unquoted = C [OK]
Hint: Use true/false for booleans, not yes/no or strings [OK]
Common Mistakes:
  • Using yes/no instead of true/false
  • Not quoting string values
  • Confusing number and string types
5. You want to send this JSON body in Postman to update a user's profile:
{
  "user": {
    "name": "Bob",
    "email": "bob@example.com",
    "preferences": {
      "notifications": false,
      "themes": ["dark", "blue"]
    }
  }
}

Which of the following changes will correctly add a new preference "language" set to "en" inside "preferences"?
hard
A. { "user": { "name": "Bob", "email": "bob@example.com", "preferences": { "notifications": false, "themes": ["dark", "blue"], "language": "en" } } }
B. { "user": { "name": "Bob", "email": "bob@example.com", "preferences": { "notifications": false, "themes": ["dark", "blue"] }, "language": "en" } }
C. { "user": { "name": "Bob", "email": "bob@example.com", "preferences": { "notifications": false, "themes": ["dark", "blue"] }, "preferences.language": "en" } }
D. { "user": { "name": "Bob", "email": "bob@example.com", "preferences": { "notifications": false, "themes": ["dark", "blue"] }, "preferences": { "language": "en" } } }

Solution

  1. Step 1: Understand nested object update in JSON

    To add a new key inside "preferences", it must be inside the existing "preferences" object.
  2. Step 2: Check each option's structure

    { "user": { "name": "Bob", "email": "bob@example.com", "preferences": { "notifications": false, "themes": ["dark", "blue"], "language": "en" } } } adds "language": "en" inside "preferences" correctly. { "user": { "name": "Bob", "email": "bob@example.com", "preferences": { "notifications": false, "themes": ["dark", "blue"] }, "language": "en" } } adds "language" outside "preferences". { "user": { "name": "Bob", "email": "bob@example.com", "preferences": { "notifications": false, "themes": ["dark", "blue"] }, "preferences.language": "en" } } uses invalid key "preferences.language". { "user": { "name": "Bob", "email": "bob@example.com", "preferences": { "notifications": false, "themes": ["dark", "blue"] }, "preferences": { "language": "en" } } } overwrites "preferences" object, losing existing keys.
  3. Final Answer:

    { "user": { "name": "Bob", "email": "bob@example.com", "preferences": { "notifications": false, "themes": ["dark", "blue"], "language": "en" } } } -> Option A
  4. Quick Check:

    Nested keys must be inside existing objects = A [OK]
Hint: Add new keys inside existing nested objects, not outside [OK]
Common Mistakes:
  • Adding keys outside nested objects
  • Using dot notation as key name
  • Overwriting entire nested objects accidentally
Recommended

Ready to prove it?

Pass the test and this pattern moves unknown strong while earning +1 Grip toward your certificate.

10 questions~5 mineasy hard