JSON to PHP Array Converter
Convert JSON data to PHP array syntax instantly. Supports short and long array syntax, trailing commas, and variable assignment.
100% client-side. Your data never leaves your browser.
In Laravel
At run time you do not need this conversion. json_decode($json, true) returns the same array, and an array cast on an Eloquent attribute decodes a JSON column each time you read it.
protected function casts(): array
{
return [
'options' => 'array',
];
}
The converter helps when the array goes into source code. The common case is a feature test. Copy the JSON your endpoint returns, convert it, and keep the keys you care about. assertJson() passes when the response contains that fragment, so extra keys do not fail the test. Use assertExactJson() when they should.
public function test_show_returns_the_order(): void
{
$this->getJson('/api/orders/42')
->assertOk()
->assertJson([
'id' => 42,
'status' => 'paid',
'items' => [
['sku' => 'TS-1001', 'quantity' => 2],
],
]);
}
The same goes for fake API responses in Http::fake() and for rows in a seeder.
Laravel 13.x docs: Testing JSON APIs, Array casting, Faking HTTP responses
Related Tools
Modern PHP Syntax
Choose between short array syntax [] or traditional array() to match your codebase conventions.
Deep Nesting
Handles any depth of nested JSON objects and arrays. Produces clean, properly indented PHP code ready to paste into your project.
Configurable Output
Customize quoting style, trailing commas, variable assignment, and indentation to match your PHP coding standards.
Need something custom built?
I build custom Laravel tools, web apps, and SaaS platforms. If you need something beyond off-the-shelf, let's talk.
ContactFrequently Asked Questions
Why does an empty object {} become []?
PHP has one array type for lists and for objects, so an empty JSON object and an empty JSON array both become []. json_decode('{}', true) does the same.
If an API needs {} back, use new \stdClass() or (object) [] for that value. json_encode() turns both into {}.
Why did a long numeric ID change after converting?
The converter parses your JSON in the browser, and JavaScript stores every number as a 64-bit float. Integers above 9,007,199,254,740,991 lose precision: 9007199254740993 comes out as 9007199254740992.
PHP is safe up to PHP_INT_MAX (9,223,372,036,854,775,807 on 64-bit builds). Above that, json_decode() returns a float unless you pass JSON_BIGINT_AS_STRING. If your IDs are this long, send them as strings.
Why did the key order change?
The converter parses your JSON in the browser, and JavaScript puts keys that are whole numbers, such as "10" and "2", first and in ascending order. Other keys keep their order. PHP's json_decode() keeps the original order, so this only matters for arrays you paste from the converter. If the order matters, check the output, or ask the API for a list of objects in place of an object keyed by ID.