A store dashboard gets its orders from an API as one long JSON string, and the chart code needs a real, typed list. That’s the everyday reason to convert JSON to array in TypeScript.
The short version is JSON.parse() plus a type annotation, then a runtime check so bad records can’t sneak in:
const orders: Order[] = JSON.parse(json);
In this tutorial, I’ll convert JSON to array in TypeScript by building a small order loader step by step. Every output comes from a real run on TypeScript 7.0.2 and Node.js v22.22.2 with --strict on.
Here’s what we’re building: a loader that accepts a JSON array or object, drops bad records and survives broken JSON.

Before You Start: The Sample Orders JSON
You need Node.js and TypeScript 5+ with strict mode. Each order in our sample has three fields, described by an Order interface (see TypeScript interfaces for arrays of objects):
| Field | Type | Notes |
|---|---|---|
| id | number | Order number, 5001-5003 |
| customer | string | Jenna Morales, Tyler Brooks, Dana Whitfield |
| total | number | USD: 89.50, 142.25, 37.00 |
Step 1: Parse the JSON String into a Typed Array
First, the quickest working conversion. The annotation tells your editor each item’s shape:
interface Order {
id: number;
customer: string;
total: number;
}
const json = `[
{"id": 5001, "customer": "Jenna Morales", "total": 89.5},
{"id": 5002, "customer": "Tyler Brooks", "total": 142.25},
{"id": 5003, "customer": "Dana Whitfield", "total": 37}
]`;
const orders: Order[] = JSON.parse(json);
console.log(Array.isArray(orders), orders.length, "orders");
console.log(orders.map((o) => o.customer));
Output:
true 3 orders
[ 'Jenna Morales', 'Tyler Brooks', 'Dana Whitfield' ]
![typescript json parse string to typed array vscode VS Code running JSON.parse on the orders string with an Order[] annotation; the terminal prints true 3 orders and three customer names](https://pythonguides.com/wp-content/uploads/2026/11/typescript-json-parse-string-to-typed-array-vscode.png)
Checkpoint: the terminal prints true 3 orders and the three customer names.
JSON.parse() returns any, so the Order[] annotation is a promise you make, not a check. For a project file, importing the JSON file gives you types for free.
Step 2: Confirm the Parsed Value Is an Array
Next, we stop trusting any. Typing the result as unknown forces a check before use:
const json = `[{"id": 5001, "total": 89.5}]`;
const data: unknown = JSON.parse(json);
console.log(data.length);
Output:
orders_unknown.ts(4,13): error TS18046: 'data' is of type 'unknown'.

TypeScript refuses to read .length until you prove what the value is. I use Array.isArray(data) as that proof; the finished loader below relies on it.
Checkpoint: tsc reports error TS18046: 'data' is of type 'unknown'. An empty array still passes, so pair this with checking if an array is null or empty.
Step 3: Validate Each JSON Record with a Type Guard
Now, we check every item. Here Tyler’s total arrives as the string "142.25". A type guard (a function returning v is Order) filters it out; checking if an object implements an interface explains the pattern:
interface Order {
id: number;
customer: string;
total: number;
}
function isOrder(v: unknown): v is Order {
if (typeof v !== "object" || v === null) return false;
const o = v as Record<string, unknown>;
return typeof o.id === "number"
&& typeof o.customer === "string"
&& typeof o.total === "number";
}
const json = `[
{"id": 5001, "customer": "Jenna Morales", "total": 89.5},
{"id": 5002, "customer": "Tyler Brooks", "total": "142.25"},
{"id": 5003, "customer": "Dana Whitfield", "total": 37}
]`;
const data: unknown[] = JSON.parse(json);
const orders = data.filter(isOrder); // Order[]
const bad = data.filter((v) => !isOrder(v));
console.log("Valid:", orders.map((o) => o.id));
console.log("Rejected:", bad);
Output:
Valid: [ 5001, 5003 ]
Rejected: [ { id: 5002, customer: 'Tyler Brooks', total: '142.25' } ]

Checkpoint: Valid: [ 5001, 5003 ], with order 5002 listed under Rejected.
Since isOrder is a type predicate, filter() returns Order[] (see filtering arrays in TypeScript).
Step 4: Turn a JSON Object into an Array with Object.values()
Some APIs send an object keyed by ID instead of an array. Same orders, new shape:
type Sale = { customer: string; total: number };
const json = `{
"5001": {"customer": "Jenna Morales", "total": 89.5},
"5002": {"customer": "Tyler Brooks", "total": 142.25}
}`;
const byId: Record<string, Sale> = JSON.parse(json);
const sales = Object.values(byId);
const withIds = Object.entries(byId).map(
([id, s]) => ({ id: Number(id), ...s }),
);
console.log(sales);
console.log(withIds);
Output:
[
{ customer: 'Jenna Morales', total: 89.5 },
{ customer: 'Tyler Brooks', total: 142.25 }
]
[
{ id: 5001, customer: 'Jenna Morales', total: 89.5 },
{ id: 5002, customer: 'Tyler Brooks', total: 142.25 }
]

Checkpoint: two arrays, and the second has id: 5001 and id: 5002 back as numbers. For plain objects, see converting an object to an array in TypeScript.
Test the JSON-to-Array Order Loader
The finished loadOrders() combines all four steps:
interface Order {
id: number;
customer: string;
total: number;
}
function isOrder(v: unknown): v is Order {
if (typeof v !== "object" || v === null) return false;
const o = v as Record<string, unknown>;
return typeof o.id === "number"
&& typeof o.customer === "string"
&& typeof o.total === "number";
}
function loadOrders(text: string) {
try {
const data: unknown = JSON.parse(text);
const list = Array.isArray(data) ? data : Object.values(data ?? {});
const orders = list.filter(isOrder);
return { orders, skipped: list.length - orders.length };
} catch (err) {
console.log("Bad JSON:", (err as Error).message);
return { orders: [] as Order[], skipped: 0 };
}
}
const json = `[
{"id": 5001, "customer": "Jenna Morales", "total": 89.5},
{"id": 5002, "customer": "Tyler Brooks", "total": 142.25},
{"id": 5003, "customer": "Dana Whitfield", "total": 37}
]`;
const { orders, skipped } = loadOrders(json);
const total = orders.reduce((sum, o) => sum + o.total, 0);
console.log(`${orders.length} orders, ${skipped} skipped,`,
`$${total.toFixed(2)}`);
loadOrders(`[{"id": 5004,}]`);
Output:
3 orders, 0 skipped, $268.75
Bad JSON: Expected double-quoted property name in JSON at position 13 (line 1 column 14)
It returns three orders totaling $268.75 with nothing skipped. The trailing comma in the last call throws a SyntaxError, which the loader logs instead of crashing. To reshape the result for a chart, see mapping an array of objects in TypeScript.
Troubleshooting: Why Does JSON.parse() Throw a SyntaxError?
- Trailing commas or single quotes: JSON allows neither; fix the source or the loader logs
Bad JSON. - Dates stay strings:
JSON.parse()never createsDateobjects; map them withnew Date().
Important: as Order[] and annotations don’t check anything at runtime.
Where to Take It Next with JSON Arrays
Generate the Order interface from a sample payload with converting JSON to a TypeScript interface. Going the other way? See converting objects to JSON in TypeScript.
A few more TypeScript array guides pair well with this one:
- Arrays of objects in TypeScript
- Remove undefined values from an array in TypeScript
- Get unique values from an array of objects in TypeScript
Frequently Asked Questions
How do I convert JSON to an array in TypeScript?
Call JSON.parse() on the string and annotate the result as Order[].
Does JSON.parse() check the type in TypeScript?
No. It returns any, so validate items with a type guard.
How do I convert a JSON object to an array?
Parse it, then use Object.values() for the values or Object.entries() to keep the keys.
Why should I type JSON.parse() as unknown?
It forces a check, like Array.isArray(), before use.
How do I handle invalid JSON?
Wrap JSON.parse() in try...catch; invalid input throws a SyntaxError.
Where is JSON.parse() documented?
See JSON.parse() on MDN.

Bijay Kumar is a 13-time Microsoft MVP with more than 18 years in software development, and the founder of Python Guides and TSinfo Technologies. He started out building .NET and SharePoint solutions at HP, TCS and KPIT before moving into Python, machine learning and AI, and he also builds web apps with TypeScript and React. He writes the tutorials here himself, and every example is run before publishing so you see the real output. More about Bijay · Microsoft MVP profile · LinkedIn