Home/Tutorials/JavaScript/Fetch and JSON

0 of 3 saved

JavaScript5 min read

Fetch and JSON

Read this chapter, write the program on this page, then pass a short check to open the next one.

Talk to HTTP APIs.

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.