JSON to Node.js Types

Turn a Node.js API request or response body into a TypeScript interface ortype — pick whichever style fits your Express, Fastify, or NestJS project. Conversion runs entirely in your browser; your data is never sent anywhere.

Style
TypeScript output
// Your generated interfaces will appear here.

Typing a Node.js API response

  1. Copy a real response body from your Node.js API (Express, Fastify, NestJS) — from Postman, curl -v, or a console.log.
  2. Paste it into the JSON input panel, or click Load sample.
  3. Pick interface or type depending on how you plan to extend or compose it.
  4. Copy the output into a types.ts or dto.ts file and import it in your route handler or service.

Why type your API layer

  • ✓ Catch a renamed or removed field at compile time, not in production
  • ✓ Autocomplete on request/response bodies in your editor
  • ✓ A single source of truth shared between a Node backend and a TypeScript frontend
  • ✓ Safer refactors across controllers, services, and DTOs

Example: an Express JSON response

res.json(...) payload

{
  "id": 101,
  "email": "user@example.com",
  "roles": ["admin", "editor"],
  "profile": {
    "displayName": "Tayyab",
    "avatarUrl": null
  }
}

Generated type

export type Profile = {
  displayName: string;
  avatarUrl: string | null;
};

export type RootObject = {
  id: number;
  email: string;
  roles: string[];
  profile: Profile;
};

FAQs

Should I use interface or type for Node.js API responses?

Either works for typing a response body. "interface" is usually preferred for objects you may extend later (for example, a base ApiResponse that specific endpoints add fields to), since interfaces support declaration merging and "extends". "type" is often preferred for request/response unions, like a result that is either a success or an error shape. This tool lets you generate both from the same JSON with one click.

Can I use this for an Express request body or response payload?

Yes. Paste a sample request body or a response from an endpoint (e.g. captured from Postman, curl, or a log) to generate a type you can import into an Express/Fastify/NestJS route handler, a DTO, or a validation schema.

Does this work for CommonJS projects, not just ESM?

The generated interfaces and type aliases are plain TypeScript declarations with no import/export runtime behavior beyond "export", so they work the same whether your Node project compiles to CommonJS or ESM — only your tsconfig "module" setting changes, not this output.

How are nested objects and arrays from a Node API response handled?

Nested objects become their own named types, and arrays of objects are merged into a single item type with optional fields where entries disagree — exactly what a real paginated API list response typically needs.

Does my JSON get sent to a server?

No. Everything runs client-side in your browser. This matters for Node.js API responses in particular, since they often contain real user or account data you should not paste into a third-party backend.

Related reading