Fetch and JSON
fetch returns a Promise for an HTTP response. response.json() parses JSON bodies. In Node Write tasks you may mock with Promise.resolve instead of a real network.
- Check response.ok before trusting the body.
- JSON.stringify / JSON.parse move data across the wire.
- Handle network errors in try/catch.
const payload = JSON.stringify({ ok: true });
const data = JSON.parse(payload);
console.log(data.ok);
After you read this chapter, use Write (when available) and Quiz on this page to lock it in.