JSON to PHP Array
Convert JSON strings into PHP array syntax (associative or indexed)
Convert JSON into PHP array code
API responses and exported settings usually come as JSON, but PHP projects often want the same data as a native array: a Laravel config file, a test fixture, a seed list or a mock response. Rewriting braces, colons and quotes by hand is tedious and easy to get wrong. This tool takes a JSON string and prints it as PHP array syntax using square brackets and the familiar arrow between keys and values.
How to convert
- Paste your JSON into the Source JSON box. Use Load Sample to see an example object, or Clear to empty the field.
- Click Convert to PHP Array.
- Read the result in the PHP Array Output panel and press Copy to put it on your clipboard.
If the text is not valid JSON, an alert says so and nothing is produced. Editing the input hides the previous result, so you never copy stale output.
What the output looks like
- Objects and lists become nested [ ... ] blocks indented by four spaces per level.
- Every key is written in single quotes followed by =>, with a trailing comma after each item except the last.
- Strings are wrapped in single quotes; numbers and true or false are written as they are; null becomes null.
Where it saves time
- Copying a sample API payload into a PHPUnit test as an expected array.
- Turning a JSON settings export into a config file.
- Building seed data for a database seeder from an existing dataset.
- Documenting a request body in PHP code examples.
Things to check in the result
The converter handles values simply, so a few points deserve a glance. Text that contains a single quote or a backslash is not escaped, meaning a value such as O'Brien needs a manual backslash before the apostrophe. JSON lists are written with their index as a quoted key, for example '0' => 'first', rather than as a bare list; PHP treats numeric string keys like integer keys, so lookups still work, but you may prefer to delete the keys by hand for tidier code. Very large numbers follow JavaScript rounding rules before they reach the output.
Everything is processed by JavaScript in your browser after you press the button. Review the code before pasting it into a project, especially for strings with special characters.
Related Tools