Skip to content

responseJsonMethods

Prefer Response.json() over new Response(JSON.stringify(...)) for JSON responses.

✅ This rule is included in the ts stylistic presets.

The Response.json() static method provides a cleaner way to create JSON responses compared to manually calling new Response(JSON.stringify(data)). Using Response.json() is more concise and automatically sets the Content-Type header to application/json.

This rule flags cases where new Response(JSON.stringify(data)) can be replaced with Response.json(data).

new
var Response: new (body?: BodyInit, init?: ResponseInit) => Response
Response
(
var JSON: JSON

An intrinsic object that provides functions to convert JavaScript values to and from the JavaScript Object Notation (JSON) format.

JSON
.
JSON.stringify(value: any, replacer?: (this: any, key: string, value: any) => any, space?: string | number): string (+1 overload)

Converts a JavaScript value to a JavaScript Object Notation (JSON) string.

@paramvalue A JavaScript value, usually an object or array, to be converted.

@paramreplacer A function that transforms the results.

@paramspace Adds indentation, white space, and line break characters to the return-value JSON text to make it easier to read.

@throws{TypeError} If a circular reference or a BigInt value is found.

stringify
(
const data: any
data
));
new
var Response: new (body?: BodyInit, init?: ResponseInit) => Response
Response
(
var JSON: JSON

An intrinsic object that provides functions to convert JavaScript values to and from the JavaScript Object Notation (JSON) format.

JSON
.
JSON.stringify(value: any, replacer?: (this: any, key: string, value: any) => any, space?: string | number): string (+1 overload)

Converts a JavaScript value to a JavaScript Object Notation (JSON) string.

@paramvalue A JavaScript value, usually an object or array, to be converted.

@paramreplacer A function that transforms the results.

@paramspace Adds indentation, white space, and line break characters to the return-value JSON text to make it easier to read.

@throws{TypeError} If a circular reference or a BigInt value is found.

stringify
({
message: string
message
: "ok" }));
new
var Response: new (body?: BodyInit, init?: ResponseInit) => Response
Response
(
var JSON: JSON

An intrinsic object that provides functions to convert JavaScript values to and from the JavaScript Object Notation (JSON) format.

JSON
.
JSON.stringify(value: any, replacer?: (this: any, key: string, value: any) => any, space?: string | number): string (+1 overload)

Converts a JavaScript value to a JavaScript Object Notation (JSON) string.

@paramvalue A JavaScript value, usually an object or array, to be converted.

@paramreplacer A function that transforms the results.

@paramspace Adds indentation, white space, and line break characters to the return-value JSON text to make it easier to read.

@throws{TypeError} If a circular reference or a BigInt value is found.

stringify
(
const data: any
data
), {});
new
var Response: new (body?: BodyInit, init?: ResponseInit) => Response
Response
(
var JSON: JSON

An intrinsic object that provides functions to convert JavaScript values to and from the JavaScript Object Notation (JSON) format.

JSON
.
JSON.stringify(value: any, replacer?: (this: any, key: string, value: any) => any, space?: string | number): string (+1 overload)

Converts a JavaScript value to a JavaScript Object Notation (JSON) string.

@paramvalue A JavaScript value, usually an object or array, to be converted.

@paramreplacer A function that transforms the results.

@paramspace Adds indentation, white space, and line break characters to the return-value JSON text to make it easier to read.

@throws{TypeError} If a circular reference or a BigInt value is found.

stringify
(
const data: any
data
), {
ResponseInit.headers?: HeadersInit
headers
: { "content-type": "application/json" },
});

This rule is not configurable.

If you need to pass additional options to JSON.stringify() like a replacer or space parameter, you’ll need to use the manual approach. Similarly, if you need to set custom response options like status or additional headers beyond Content-Type, use new Response() directly.

Made with ❤️‍🔥 around the world by the Flint team and contributors.