main
Branches
main (6.4.1)dev
Versions
6.4.1v4/5.xv3.x
json

json

A shortcut for:

new Response(JSON.stringify(someValue), {
  headers: {
    "Content-Type": "application/json; utf-8",
  },
});

Typically used in loaders:

import { json } from "react-router-dom";

const loader = async () => {
  const data = getSomeData();
  return json(data);
};

See also:

Docs and examples CC 4.0
Edit