JSON to TypeScript, a PHP DTO, or a Laravel array
Last reviewed 1 November 2026
Paste a JSON object, or an array of objects, into the JSON converter and pick Laravel, TypeScript, PHP DTO, or CSV. Laravel prints PHP array syntax for the whole value, nested objects included. TypeScript drafts export interface Root from the first object only, and a nested object becomes another interface. The PHP DTO is a single class named DataTransferObject, also taken from the first object, and a nested object is typed as array. CSV keeps the top-level keys and writes a nested object into one cell. Invalid JSON shows the parse error and leaves the output empty. If the text needs indenting before you convert it, use the JSON formatter.
What each output is
The Sample button fills this array. Every block below is the converter’s output for that text.
[
{"id": 1, "name": "Ada", "role": "engineer", "meta": {"active": true}},
{"id": 2, "name": "Linus", "role": "founder", "meta": {"active": false}}
]Laravel walks the whole array. Each object becomes a PHP array, true and false stay booleans, and meta stays nested.
[
[
'id' => 1,
'name' => 'Ada',
'role' => 'engineer',
'meta' => [
'active' => true,
],
],
[
'id' => 2,
'name' => 'Linus',
'role' => 'founder',
'meta' => [
'active' => false,
],
],
]TypeScript ignores Linus. The interface is drafted from Ada, the first object. meta is a second interface because that value is an object. The root name is always Root.
export interface Root {
id: number;
name: string;
role: string;
meta: Meta;
}
export interface Meta {
active: boolean;
}The PHP DTO is also drafted from Ada only. There is no child class. meta is public array $meta, and the constructor copies $data['meta'] through as an array. The class name does not change.
<?php
declare(strict_types=1);
class DataTransferObject
{
public int $id;
public string $name;
public string $role;
public array $meta;
public function __construct(array $data = [])
{
$this->id = $data['id'] ?? null;
$this->name = $data['name'] ?? null;
$this->role = $data['role'] ?? null;
$this->meta = $data['meta'] ?? null;
}
}CSV uses the keys of every row, but only the top level. meta is one column. The cell is the nested object encoded as JSON, with quotes escaped for CSV.
id,name,role,meta
1,Ada,engineer,"{""active"":true}"
2,Linus,founder,"{""active"":false}"Download uses converted.php for Laravel and the PHP DTO, converted.ts for TypeScript, and converted.csv for CSV. Conversion runs in the browser. The page does not send the paste to an API.
A second array, with keys that differ
This input is two objects that do not share a shape. The first has name. The second has email and no name.
[{"id":1,"name":"Ada"},{"id":2,"email":"linus@example.com"}]Laravel still prints both rows, so the second row keeps email. TypeScript and the PHP DTO do not. Both are drafted from the first object, so the result has id and name only. CSV builds the header from every top-level key it sees, and a missing key is an empty cell.
export interface Root {
id: number;
name: string;
}id,name,email
1,Ada,
2,,linus@example.comThe PHP class for that first object is public int $id and public string $name, assigned with $data['id'] ?? null and $data['name'] ?? null. email is not a property.
Limits that match the page
CSV keeps top-level keys only. A nested object becomes one cell, not extra columns. In the sample, active is inside meta, so it is not its own header. An array value is also one cell: {"id":1,"tags":[]} converts to a tags cell of [].
Invalid JSON shows the parse error and leaves the output empty. { produces Expected property name or '}' in JSON at position 1 (line 1 column 2). A trailing comma, as in {"a":1,}, produces Expected double-quoted property name in JSON at position 7 (line 1 column 8). An empty box produces Unexpected end of JSON input. The output is empty for each of them. Repair the text in the JSON formatter, then convert again.
For an empty array, the four formats disagree. Laravel prints []. TypeScript prints an empty Root interface with a blank line between the braces. The PHP DTO prints a DataTransferObject that has declare(strict_types=1), no properties, and an empty constructor. CSV does not convert it. The error is CSV conversion expects an array of objects. and the output is cleared.
Nulls stay null when they are property values. For {"name":null,"age":null,"meta":null}, Laravel writes null for each key, TypeScript types each field as null, the PHP DTO types each property as mixed, and CSV writes the headers with an empty row underneath.
[1,"a",true,null] becomes a PHP list of those four values in Laravel. TypeScript prints export interface Root {} with nothing inside, because the first item is a number, not an object. The PHP DTO prints the stub class whose only body is the comment Provide a JSON object to generate properties. CSV rejects it with CSV conversion expects an array of objects. A whole number such as 1 is int on the PHP DTO, 1.5 is float, and TypeScript types both as number.
Common mistakes
A bad paste is not kept in part. A trailing comma clears the output. The JSON formatter is where to remove it. JSON does not allow a comma after the last value.
Shipping the PHP DTO unchanged. meta is array, not a class. The constructor line is $this->id = $data['id'] ?? null on a property declared public int $id, and the other fields follow that pattern. A missing key is null in that assignment. The class name is always DataTransferObject.
Leaving a hyphen in a key. For {"first-name":"Ada","role":"engineer"}, Laravel quotes it, which is valid array syntax: 'first-name' => 'Ada'. TypeScript emits first-name: string; and the PHP DTO emits public string $first-name;.
Trusting the child interface name. An array of objects drops a single trailing s from the key, then Pascal-cases it. items becomes Item, so the field is items: Item[]. status becomes Statu, so the field is status: Statu[] with export interface Statu. The PHP DTO types both properties as array.
Common questions
Which object is used for TypeScript and the PHP DTO?
The first object, when the root value is an array. One JSON object is used whole. Later rows still appear in the Laravel array, and their top-level keys still join the CSV header.
Does CSV split a nested object into columns?
No. The nested object is one cell of JSON text. Inner quotes are doubled so the row stays valid CSV. active in the sample is not a header.
What does invalid JSON produce?
An empty output and the parse error. {, {"a":1,}, and an empty input were all cleared. Nothing from the previous conversion is left behind.
Why is meta typed as array on the PHP class?
An object value maps to array. The draft does not emit a class for it. TypeScript does emit interface Meta for the same value, and Laravel nests a PHP array.
Does the converter upload the JSON?
No. Parsing and conversion run in the browser. Copy and Download use the text already on the page. The blocks above came from the JSON converter.
Related guides
Related tools
JSON Formatter & Validator
Beautify, minify, validate, and explore JSON with instant error highlighting — 100% in your browser.
SQL Formatter
Beautify messy SQL queries with consistent indentation and keyword casing.
Base64 Encoder / Decoder
Encode and decode Base64 text or convert images to Base64 data URIs instantly.