© 2026 Hedgehog Software, LLC

TwitterGitHubDiscord
More
CommunitiesDocsAboutTermsPrivacy
Search
Star
Setup for Free
SupabaseS
Supabase•4y ago•
3 replies
Ro

JSON parsing issues with Supabase Edge Functions

It's my first time using edge functions from the browser, so I set up the test methods from docs. I can't get past this error. Can anyone help?

error
: 
"\"[object Object]\" is not valid JSON"
error
: 
"\"[object Object]\" is not valid JSON"


I have a function in my browser client code like this:
export const test = async (name) => {
  const { data, error } = await supabaseClient.functions.invoke('hello', {
    body: { foo: name }
  });
  console.log('data: ', data);
  return data?.message;
};
export const test = async (name) => {
  const { data, error } = await supabaseClient.functions.invoke('hello', {
    body: { foo: name }
  });
  console.log('data: ', data);
  return data?.message;
};


And the edge function:
serve(async (req) => {
  // This is needed if you're planning to invoke your function from a browser.
  if (req.method === 'OPTIONS') {
    return new Response('ok', { headers: corsHeaders })
  }

  try {
    const { body } = await req.json()
    const data = {
      message: `Hello ${JSON.stringify(body)}!`,
    }

    return new Response(JSON.stringify(data), {
      headers: { ...corsHeaders, 'Content-Type': 'application/json' },
      status: 200,
    })
  } catch (error) {
    return new Response(JSON.stringify({ error: error.message }), {
      headers: { ...corsHeaders, 'Content-Type': 'application/json' },
      status: 400,
    })
  }
})
serve(async (req) => {
  // This is needed if you're planning to invoke your function from a browser.
  if (req.method === 'OPTIONS') {
    return new Response('ok', { headers: corsHeaders })
  }

  try {
    const { body } = await req.json()
    const data = {
      message: `Hello ${JSON.stringify(body)}!`,
    }

    return new Response(JSON.stringify(data), {
      headers: { ...corsHeaders, 'Content-Type': 'application/json' },
      status: 200,
    })
  } catch (error) {
    return new Response(JSON.stringify({ error: error.message }), {
      headers: { ...corsHeaders, 'Content-Type': 'application/json' },
      status: 400,
    })
  }
})
Supabase banner
SupabaseJoin
Supabase gives you the tools, documentation, and community that makes managing databases, authentication, and backend infrastructure a lot less overwhelming.
45,816Members
Resources

Similar Threads

Was this page helpful?
Recent Announcements

Similar Threads

Vercel supabase with edge functions
SupabaseSSupabase / help-and-questions
4y ago
Supabase Edge Functions authentication
SupabaseSSupabase / help-and-questions
2w ago
Edge functions supabase error
SupabaseSSupabase / help-and-questions
5mo ago
Supabase Edge Functions with Self Hosted
SupabaseSSupabase / help-and-questions
2mo ago