# A JSON array with mixed types

**A single object shape.**

## Input

```json
{
  "values": [1, "two", true, null]
}
```

## TypeScript

```typescript
export interface Root {
  values: (number | string | boolean | null)[];
}
```

## Zod

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

export const RootSchema = z.object({
  values: z.array(z.union([z.number(), z.string(), z.boolean()]).nullable()),
});
```

## Warnings

### Mixed types merged into a union (info)

`values[]` contained more than one type, so the output is a union of everything observed. Note that typing from the first element alone — the usual shortcut — would have produced a type that rejects the rest of this sample.

### 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/mixed-type-json-array
JSON API: `POST https://json-to-types.gumballtools.com/api/v1/convert`
MCP endpoint: `https://json-to-types.gumballtools.com/api/mcp`
