# A JSON array to a TypeScript type

**An array of one object shape.**

## Input

```json
[
  { "id": 1, "name": "Ada" },
  { "id": 2, "name": "Grace", "admin": true }
]
```

## TypeScript

```typescript
export interface RootItem {
  id: number;
  name: string;
  admin?: boolean;
}

export type Root = RootItem[];
```

## Zod

```typescript
import { z } from 'zod';

export const RootItemSchema = z.object({
  id: z.number(),
  name: z.string(),
  admin: z.boolean().optional(),
});

export const RootSchema = z.array(RootItemSchema);
```

## Warnings

### Optionality inferred from one sample (caution)

`[].admin` was missing from at least one object in the sample and is therefore marked optional. A single sample cannot distinguish "sometimes omitted" from "omitted in this particular payload".

**Fix:** Check these against the real schema. Absent means optional; a null value would instead mean present-and-nullable, which is a different type.

### Whole numbers are still `number` (info)

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()`.

---

Canonical URL: https://json-to-types.gumballtools.com/types/json-array-to-typescript
JSON API: `POST https://json-to-types.gumballtools.com/api/v1/convert`
MCP endpoint: `https://json-to-types.gumballtools.com/api/mcp`
