How to pass JSON through Edge Functions Chain

If I understand Chaining correctly, I’m able to pass content from one Edge Function to another as per netlify.toml

How can I pass JSON in the same manner? I tried using context.json(value) but I don’t think context gets updated

For example:
function = “edge-json-1”
path = “/*”

function = “edge-json-2”
path = “/*”


export default async (request, context) => {
  let edgeJson1 = { hello: "world" };
  context.log("-> returning edgeJson1", edgeJson1);


export default async (request, context) => {
  let edgeJson2 = context.json();
  context.log("<- receiving context", context);
  context.log("<- receiving context.json() as edgeJson2", edgeJson2);

console log

[edge-json-1] -> returning edgeJson1 { hello: "world" }
[edge-json-2] <- receiving context {
  cookies: {
    delete: [Function: bound delete],
    get: [Function: bound get],
    set: [Function: bound set]
  geo: {
    city: "XXX",
    country: { code: "XX", name: "XXX" },
    subdivision: { code: "XX", name: "XXX" }
  json: [Function: bound json],
  log: [Function],
  next: [Function: next],
  rewrite: [Function: bound rewrite]
[edge-json-2] <- receiving context.json() as edgeJson2 Response {
  body: null,
  bodyUsed: false,
  headers: Headers { "content-type": "application/json" },
  ok: true,
  redirected: false,
  status: 200,
  statusText: "",
  url: ""

Any help would be greatly appreciated!

Hi @stevenmilstein,

context.json() is just a syntax sugar for JSON.stringify(). It’s not used to pass responses among Edge Functions. Rather, there’s probably no way to pass data to an Edge Function from another Function.

I believe you can send a POST request to the next Edge Function, but at the moment that doesn’t seem to be able to use the body. This is being investigated.

Hi @hrishikesh ,

Thanks for the insight!

Is there a GitHub Issue# I can subscribe to?

hi there @stevenmilstein - the issue is unfortunately on a private repo so we can’t share it with you, but, i see there is some active work happening on this, and we will let you know once we have something we can share with you.

Hey @stevenmilstein,

You can send POST requests to Edge Functions as mentioned before and try to consume the body as:

import { Context } from "netlify:edge";

export default async (req: Request, context: Context) => {
  const body = await req.json();

  return context.json(body);

You can use req.text(), if needed.

Let us know if that works.