Bird
0
0

You want to convert this JavaScript object to JSON string:

hard📝 Application Q9 of 15
Rest API - Request and Response Format
You want to convert this JavaScript object to JSON string:
{"name": "Anna", "age": 25, "active": false}

Which method do you use and what is the output?
Aobj.toString() -> '[object Object]'
BJSON.stringify(obj) -> '{"name":"Anna","age":25,"active":false}'
Cobj.toJSON() -> '{name: Anna, age: 25, active: false}'
DJSON.parse(obj) -> '{"name":"Anna","age":25,"active":false}'
Step-by-Step Solution
Solution:
  1. Step 1: Identify method to convert object to JSON string

    JSON.stringify converts JavaScript objects to JSON strings.
  2. Step 2: Check output format

    Output is a string with double quotes around keys and string values, booleans as false.
  3. Final Answer:

    JSON.stringify(obj) -> '{"name":"Anna","age":25,"active":false}' -> Option B
  4. Quick Check:

    Use JSON.stringify to convert object to JSON string [OK]
Quick Trick: Use JSON.stringify to convert objects to JSON strings [OK]
Common Mistakes:
  • Using JSON.parse to convert objects
  • Expecting toJSON or toString to produce JSON
  • Incorrect output format with missing quotes

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Rest API Quizzes