EditSafely

Convert a PHP Array to JSON

Create a JSON data structure from a PHP data structure.

Runs on your device, nothing uploaded

Indent
Try:

0 chars · 0 lines

Output

Create a JSON data structure from a PHP data structure.

Type or paste above to see the result here.

Example: Convert a PHP array literal

What you paste never leaves this tab

Convert a PHP Array to JSON is JavaScript that your browser has already downloaded, and it does the whole job on your own machine. On a normal site, an API response with live access tokens in it is sent to a server that can log it, cache it or keep it. Here it is read and transformed inside this tab and nowhere else.

  • No upload
  • No length limit
  • Works offline once loaded
  • Nothing stored or logged

How to use Convert a PHP Array to JSON

  1. 1. Paste your PHP array. Paste a PHP array literal, using either 'key' => value or the older array() form, into the input pane. A whole config file with <?php, return or $data = and the closing semicolon works too; print_r output is spotted and explained. The tool parses it and shows JSON on the right immediately.
  2. 2. Choose an indent. Select 2 spaces, 4 spaces or tabs for the resulting JSON. Pick whichever matches the formatting convention already used by the frontend project or API schema receiving the output.
  3. 3. Read the converted JSON. Arrow keys become colons, PHP array brackets become JSON braces or brackets depending on whether keys are sequential integers, and single-quoted strings become double-quoted JSON strings.
  4. 4. Copy the JSON. Copy the resulting JSON and paste it into an API response, a .json config file, or wherever the receiving system expects standard JSON instead of PHP syntax.

When to use Convert a PHP Array to JSON

Convert a PHP Array to JSON is for the reverse direction: taking data written as PHP syntax and turning it into standard JSON a non-PHP system can consume. It is useful whenever a value lives in a .php config file but the target audience is a JS frontend or a JSON API.

  • Exporting a Laravel config array. A Laravel config/app.php array needs to reach a JavaScript frontend as a JSON blob. Paste the array here and copy the JSON straight into the frontend's config file.
  • Migrating a legacy PHP app. An old application stores settings as PHP array() literals, and the new system expects JSON. Convert each array once during the migration instead of hand-rewriting the syntax.
  • Converting a WordPress options array. You dumped a WordPress plugin's options array with var_export and need it as JSON for a backup or an external service. Paste the dump and copy the JSON out.
  • Turning a hardcoded array into an API fixture. A PHP test file has a hardcoded array of sample data that a frontend team wants as a JSON fixture for their own mocks. Convert it once and share the file.

Examples

Convert a PHP array literal

Input

['name' => 'Ada', 'tags' => ['math', 'code']]

Output

{
  "name": "Ada",
  "tags": [
    "math",
    "code"
  ]
}

About the Convert a PHP Array to JSON tool

Convert a PHP Array to JSON is a free online tool that works entirely inside your web browser. Create a JSON data structure from a PHP 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 the Indent setting, and the result refreshes the moment you change it. 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 step is handled on your own machine rather than by a remote API.

Frequently asked questions

Does Convert a PHP Array to JSON cost anything?

Yes, it is completely free. All 2,943 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; your device's memory is the ceiling. Up to 10 MB the result updates as you type, after a short pause that grows with the size. Above 10 MB a Run button appears so typing stays smooth, and files open up to 50 MB. A very long result shows its first 2,000 lines on screen, while Copy and Download always include all of it.

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.

Related tools

All JSON Tools →