Convert JSON to a PHP Array
Create a PHP data structure from a JSON data structure. Runs entirely in your browser, so your data never leaves your device.
0 chars · 0 lines
Output
The result appears here as you type.
How to use Convert JSON to a PHP Array
- 1. Paste your JSON. Put the JSON object or array you want converted into the input pane. It parses immediately and shows the equivalent PHP array literal on the right as you type.
- 2. Pick short or long array syntax. Turn on Short [] syntax to write arrays as [] the way modern PHP style guides prefer, or leave it off for the older array() form some legacy codebases still require.
- 3. Choose an indent. Select 2 spaces, 4 spaces or tabs to match your project's coding standard. PSR-12 codebases typically use 4 spaces, while many frameworks default to 2.
- 4. Copy the PHP array. Copy the generated array literal, complete with 'key' => value syntax, and paste it straight into a .php file as a variable assignment or return statement.
When to use Convert JSON to a PHP Array
Convert JSON to a PHP Array is for turning a JSON payload into a native PHP array literal you can drop straight into source code. It saves the manual work of rewriting braces as array() and colons as arrows by hand every time a JSON sample needs to live in PHP.
- Seeding a Laravel test fixture. You have a JSON response captured from an API and need it as a PHP array inside a factory or a PHPUnit test. Paste it here and copy the array literal straight in.
- Porting a JS config into WordPress. A theme's functions.php needs the same settings that already exist as a JSON file in the frontend build. Convert it once instead of retyping every key by hand.
- Hardcoding a mock response. You want to stub an HTTP client in a PHP test without hitting a real API. Convert the sample JSON response into a PHP array and return it from the mock.
- Migrating a JSON translation file. An older CMS expects language strings as a PHP array rather than JSON. Convert the JSON translation file once and commit the resulting array file to the legacy codebase.
Examples
Convert an object to a PHP array
Input
{"name": "Ada", "tags": ["math", "code"]}Output
[
'name' => 'Ada',
'tags' => [
'math',
'code',
],
]About the Convert JSON to a PHP Array tool
Convert JSON to a PHP Array is a free online tool that works entirely inside your web browser. Create a PHP data structure from a JSON data structure. Because the processing happens on your own device, nothing you enter is uploaded, logged or stored anywhere.
This page is one of 90 JSON utilities on EditSafely. Each one does a single job well, and all of them follow the same rule: your input stays on your machine.
You can shape the output with 2 settings, including Short [] syntax and Indent, and the result refreshes the moment you change one. A worked example further down the page shows exactly what the tool produces for a real input.
Because nothing leaves your device, the tool is suitable for sensitive content such as internal documents, credentials or customer data. It also responds instantly, since every keystroke is handled on your own machine rather than by a remote API.
Frequently asked questions
Does Convert JSON to a PHP Array cost anything?
Yes, it is completely free. All 2,658 tools on EditSafely work without an account, a subscription or usage limits.
Is it safe to paste sensitive or confidential data?
No data leaves your device. The whole tool is JavaScript that runs inside your browser tab, so there is no upload, no server-side processing and no log of what you did. If you disconnect from the internet after the page loads, it keeps working.
How much text can I process at once?
There is no fixed limit. Because the work happens on your own device rather than on a shared server, the practical ceiling is your machine's memory, which comfortably handles inputs far larger than typical online tools allow.
Do I need to sign up or install anything?
Nothing to install and no account needed. Open the page in any up-to-date browser, including on a phone or tablet, and the tool is ready.
How do I use the result?
The output panel has a one-click copy button, and you can keep refining the input while you work; the result updates in place as you type.