Bird
0
0

You wrote this code to save JSON data:

medium📝 Debug Q14 of 15
Cypress - File Operations
You wrote this code to save JSON data:
cy.writeFile('user.json', '{"name": "Bob", "age": 25}')

But when you read the file, you get a string instead of an object. What is the problem?
AThe JSON data is passed as a string, not as an object
BThe file path is incorrect
Ccy.writeFile cannot write JSON data
DThe file extension must be .txt
Step-by-Step Solution
Solution:
  1. Step 1: Analyze the data argument

    The data is passed as a JSON string, not as a JavaScript object.
  2. Step 2: Understand how cy.writeFile handles data

    If you pass a string, it writes it as a string. To write JSON, pass an object directly.
  3. Final Answer:

    The JSON data is passed as a string, not as an object -> Option A
  4. Quick Check:

    Pass object, not string, to write JSON [OK]
Quick Trick: Pass object, not JSON string, to write JSON files [OK]
Common Mistakes:
  • Passing JSON as string instead of object
  • Blaming file path without checking data
  • Thinking file extension affects JSON writing

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Cypress Quizzes