Reading Response Bodies
What you'll learn: How to extract actual data from a fetch() Response using methods like .json(), .text(), .blob(), and more.
The Response Has the Data, But You Need to Unwrap It
When you call fetch(), you get a Response object back—but the actual content (the body) isn't immediately available as usable data. Think of it like receiving a package: the Response is the box, but you need to open it in the right way depending on what's inside.
The Response object provides several methods to read its body, each returning a Promise that resolves to the parsed data.
Common Body-Reading Methods
.json()
Parses the response body as JSON and returns a Promise that resolves to a JavaScript object or array.
fetch('https://api.example.com/data')
.then(response => response.json())
.then(data => {
console.log(data.name); // Access the parsed object
});
.text()
Returns the body as a plain string, useful for HTML, CSV, or plain text responses.
fetch('https://example.com/page.html')
.then(response => response.text())
.then(html => {
console.log(html); // Raw HTML string
});
.blob()
Returns the body as a Blob, perfect for images, videos, or other binary files.
fetch('https://example.com/photo.jpg')
.then(response => response.blob())
.then(imageBlob => {
const img = document.createElement('img');
img.src = URL.createObjectURL(imageBlob);
});
Other Methods
.arrayBuffer(): Raw binary data as an ArrayBuffer.formData(): Parses multipart form data
Important: You Can Only Read Once
Each Response body can only be read once. If you call .json(), you can't then call .text() on the same Response.
Key Takeaway: The Response object requires you to call the appropriate method (.json(), .text(), .blob(), etc.) to extract and parse the body content—each returns a Promise and can only be used once per response.