JSON to Types

Are JSON numbers integers or floats?

JSON has one number type. Whole values in a sample do not prove a field is an integer.

Input

{
  "count": 10,
  "ratio": 0.75,
  "id": 1000000
}

A single object shape.

1 interface · 3 fields · 1 levels deep

Where this sample is ambiguous

  • Note

    Whole numbers are still `number`

    Every numeric value in the sample was a whole number, but JSON has a single number type and cannot express the difference. The output uses `number`.

    Fix: If a field is genuinely an integer, tighten it by hand: `z.number().int()`.

TypeScript

export interface Root {
  count: number;
  ratio: number;
  id: number;
}

Zod

import { z } from 'zod';

export const RootSchema = z.object({
  count: z.number(),
  ratio: z.number(),
  id: z.number(),
});

Convert your own JSON

Paste a sample on the home page, or call the API or MCP server. This page is also available as markdown.

Related examples