Loading

Quipoin Menu

Learn • Practice • Grow

node-js / Working with JSON Files
mcq
Direction: Choose the correct option

Q1.

How do you read a JSON file and parse it in Node.js?
A. Use `fs.readJSON`
B. Use `require()` directly
C. Both A and C
D. Read with `fs.readFile` then `JSON.parse`
Direction: Choose the correct option

Q2.

What happens when you `require()` a JSON file?
A. It throws an error
B. It returns a string
C. It returns a parsed JavaScript object
D. It returns a buffer
Direction: Choose the correct option

Q3.

How do you write a JavaScript object to a JSON file?
A. Use `JSON.write`
B. Directly write the object
C. Use `fs.writeJSON`
D. Convert with `JSON.stringify` and write
Direction: Choose the correct option

Q4.

What is the purpose of `JSON.stringify(obj, null, 2)`?
A. To remove null values
B. To pretty-print with 2-space indentation
C. To convert to buffer
D. To minify the JSON
Direction: Choose the correct option

Q5.

When using `require()` for JSON, what is cached?
A. The parsed object
B. The file path
C. Nothing
D. The raw JSON string