Response.prototype.json
Takes a Response stream and reads it to completion, parsing the result as JSON
Syntax
response.json()Return Value
A Promise that resolves to the result of parsing the body text as JSON
Examples
const response = await fetch('/api/users')
const users = await response.json()
console.log(users)async function fetchJSON<T>(url: string): Promise<T> {
const res = await fetch(url)
if (!res.ok) throw new Error(`HTTP ${res.status}`)
return res.json()
}const response = await fetch('/api/config')
const { theme, locale } = await response.json()
console.log('Theme:', theme, 'Locale:', locale)Understanding Response.prototype.json
The Response.prototype.json method in JavaScript takes a Response stream and reads it to completion, parsing the result as JSON. It belongs to the Response object and is one of the most widely used methods for working with response values in modern JavaScript and TypeScript applications.
The method signature is response.json(). When called, it returns a promise that resolves to the result of parsing the body text as json. Understanding when and how to use json() helps you write more expressive, readable code.
Common use cases for Response.prototype.json include data transformation, input validation, API response processing, and building reusable utility functions. It works well alongside related methods like fetch-response-text, fetch-response-blob, fetch-response-arraybuffer, enabling you to chain operations together for complex data manipulation pipelines.
Browser support for Response.prototype.json is excellent across all modern browsers including Chrome, Firefox, Safari, and Edge. It is also fully supported in Node.js and Deno. For older environments, transpilation with Babel or a polyfill may be needed.
Browser Compatibility
Supported in all modern browsers (Chrome, Firefox, Safari, Edge) and Node.js. Part of the ECMAScript standard.
Related Methods
Response.prototype.textTakes a Response stream and reads it to completion, returning the result as a string
Response.prototype.blobTakes a Response stream and reads it to completion, returning the result as a Blob
Response.prototype.arrayBufferTakes a Response stream and reads it to completion, returning the result as an ArrayBuffer
More Response Methods
Other methods in the Response object
Related Tools
More Response Methods
Explore JavaScript Methods
Browse our complete reference of 410 JavaScript methods with syntax, examples, and explanations.