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).
72n5<3 sp ansty="le--0:#82AAFF;--1:#3B61">B0Respon3 sp>5<3(sp ansty="le--0:#82AAFF;--1:#3B61">B0JS3(sp>AB0stringi53(data)<);d ivclassNa="meco"><);d>);d>);d>72n5<3 sp ansty="le--0:#82AAFF;--1:#3B61">B0Respon3 sp>5<3(sp ansty="le--0:#82AAFF;--1:#3B61">B0JS3(sp>AB0stringi53({ message<: sp ansty="le--0:#D9F5DD;--1:#1111">1<1"sp ansty="le--0:#ECC48D;--1:#984E">4D1"sp>1<1"sp ansty="le--0:#D6DEEB;--1:#403F">53 })1"sp><);d ivclassNa="meco"><);d>);d>);d>72n5<3 sp ansty="le--0:#82AAFF;--1:#3B61">B0Respon3 sp>5<3(sp ansty="le--0:#82AAFF;--1:#3B61">B0JS3(sp>AB0stringi53(data), {}<);d ivclassNa="meco"><);d>);d>);d>72n5<3 sp ansty="le--0:#82AAFF;--1:#3B61">B0Respon3 sp>5<3(sp ansty="le--0:#82AAFF;--1:#3B61">B0JS3(sp>AB0stringi53(data),< {d ivclassNa="meec-li">53< sp ansty="le--0:#D6DEEB;--1:#403F">53headers: sp><{ sp ansty="le--0:#D9F5DD;--1:#1111">1{ sp><1"sp ansty="le--0:#ECC48D;--1:#984E">4Dcontent-ty1"sp>1<1"sp ansty="le--0:#D6DEEB;--1:#403F">531"sp><: sp ansty="le--0:#D9F5DD;--1:#1111">1<1"sp ansty="le--0:#ECC48D;--1:#984E">4Dapplication/js1"sp>1<1"sp ansty="le--0:#D6DEEB;--1:#403F">53 1"sp> {d><},d ivclassNa="meec-li">53}},d><);d ivclassNa="meco"><);d>);d>);d> 3F53Resp4<4AE. spans="tyle--0:#82AAFF;--1:#3B">61B04AE.>3F53(da<;di vdivclass="Nameexpressive-">3F53Resp4<4AE. spans="tyle--0:#82AAFF;--1:#3B">61B04AE.>3F53({ messa1<111" spans="tyle--0:#ECC48D;--1:#98">4E111"><4Dok spans="tyle--0:#D9F5DD;--1:#11">14Dok><111" spans="tyle--0:#D6DEEB;--1:#40">3F53111">< }) ;divclass="Name">< })> })> })>;di><;di vdivclass="Nameexpressive-">6E7<2new spans="tyle--0:#D6DEEB;--1:#40">32new>61B0Resp361B04<4AE. spans="tyle--0:#82AAFF;--1:#3B">61B0strin4AE.>3F53(da48483F<53, spans="tyle--0:#F78C6C;--1:#AA">053, ><9822 spans="tyle--0:#D6DEEB;--1:#40">3F59822><3)) ;divclass="Name"><2))>2))>3))>;di><;di vdivclass="Nameexpressive-">6E7<2new spans="tyle--0:#D6DEEB;--1:#40">32new>61B0Resp361B04<4AE. spans="tyle--0:#82AAFF;--1:#3B">61B0strin4AE.>3F53(data), { stat098<2404 spans="tyle--0:#D6DEEB;--1:#40">3F532404>< }) ;divclass="Name">< })> })> })>;di><;di vdivclass="Nameexpressive-">6E7<2new spans="tyle--0:#D6DEEB;--1:#40">32new>61B0Resp3F53(te;di>
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.