Return JSON
  Last reviewed:  almost 2 years ago  
  Return JSON directly from a Worker script, useful for building APIs and middleware.
If you want to get started quickly, click on the button below.
This creates a repository in your GitHub account and deploys the application to Cloudflare Workers.
export default {  async fetch(request) {    const data = {      hello: "world",    };
    return Response.json(data);  },};export default {  async fetch(request): Promise<Response> {    const data = {      hello: "world",    };
    return Response.json(data);  },} satisfies ExportedHandler;from workers import WorkerEntrypoint, Responseimport json
class Default(WorkerEntrypoint):    def fetch(self, request):        data = json.dumps({"hello": "world"})        headers = {"content-type": "application/json"}        return Response(data, headers=headers)use serde::{Deserialize, Serialize};use worker::*;
#[derive(Deserialize, Serialize, Debug)]struct Json {    hello: String,}
#[event(fetch)]async fn fetch(_req: Request, _env: Env, _ctx: Context) -> Result<Response> {    let data = Json {        hello: String::from("world"),    };    Response::from_json(&data)}import { Hono } from "hono";
const app = new Hono();
app.get("*", (c) => {  const data = {    hello: "world",  };
  return c.json(data);});
export default app;Was this helpful?
- Resources
- API
- New to Cloudflare?
- Directory
- Sponsorships
- Open Source
- Support
- Help Center
- System Status
- Compliance
- GDPR
- Company
- cloudflare.com
- Our team
- Careers
- © 2025 Cloudflare, Inc.
- Privacy Policy
- Terms of Use
- Report Security Issues
- Trademark