Browse API 1 documentation
response.json()
Parse a native network response body as JSON.
Mango 3.1+View Markdown
Parse a native network response body as JSON.
Signature
ts
response.json(): unknown
Availability
On the response returned by grove.network.request. It is not a global function.
Parameters
None.
Return value
Returns the parsed JSON value synchronously. The result can be an object, array, string, number, boolean, or null.
Behavior and errors
Decodes UTF-8 then calls JSON.parse; malformed or empty JSON throws synchronously. No content-type or schema validation is performed. It does not consume the response bytes; repeated calls parse again. Handle both the request rejection and parsing error.
Example
js
try {
const response = await grove.network.request('https://api.example.com/status')
if (!response.ok) throw new Error('Status request failed')
const value = response.json()
if (!value || typeof value !== 'object' || typeof value.ready !== 'boolean') {
throw new Error('Unexpected status response')
}
} catch {
console.error('Could not read service status.')
}