Skip to content
XUtilHub

JSON to PHP Array Converter

Convert JSON to PHP array syntax using short [] arrays and => notation. Ready to paste into your PHP code.

  • Free, no sign-up
  • Runs in your browser, nothing uploaded
Input
Output

About the JSON to PHP Array

Convert JSON into PHP array code with short array syntax, properly escaped strings and nested arrays.

Key features

  • Modern short array syntax [] with => notation
  • Properly escaped single-quoted strings
  • Nested arrays indented for readability
  • true/false/null mapped to PHP literals
  • Output wrapped in a ready-to-use <?php file
  • Download as data.php

Convert JSON into PHP code

PHP projects are full of array-based configuration: Laravel's config/*.php, Symfony bundles, WordPress plugin settings, database seeders, test fixtures and translation files. When your data starts life as JSON, from an API, a design tool or another service, converting it to a PHP array literal saves tedious manual rewriting.

Example

{
  "app": "XUtilHub",
  "debug": false,
  "features": ["json", "pdf"],
  "mail": { "host": "smtp.example.com", "port": 587 }
}
<?php

$data = [
    'app' => 'XUtilHub',
    'debug' => false,
    'features' => [
        'json',
        'pdf',
    ],
    'mail' => [
        'host' => 'smtp.example.com',
        'port' => 587,
    ],
];

Mapping

JSONPHP
{"k": v}['k' => v]
[1, 2][1, 2]
"text"'text'
true / falsetrue / false
nullnull
3.53.5

Laravel config example

Save the output as config/services_extra.php, replace $data = with return, and access values with config('services_extra.mail.host').

json_decode vs. a PHP array literal

json_decode($json, true)Array literal
Data changes at runtime✅❌
Opcache-friendly config⚠️ parse on every request✅
Readable in code review⚠️✅
Supports comments❌✅

Generating Java instead? See JSON to Java. Need a string literal for PHP? JSON to String has a PHP mode.

How to use the JSON to PHP Array

  1. Paste your data into the input box, upload a file, or click Sample to try it out.
  2. Adjust the options above the editor if you need to (indentation, delimiter, and so on).
  3. The PHP Array appears instantly in the output panel. Any errors are shown with their line and column.
  4. Click Copy to copy the result, or Download to save it as a file.

Frequently asked questions

Why not just use json_decode at runtime?

For dynamic data, json_decode($json, true) is the right choice. Converting to a PHP array literal is useful for config files, fixtures, seeders and Laravel or Symfony config, where you want plain PHP code.

Does it produce objects or arrays?

Associative arrays, which is what most PHP config files and frameworks use. JSON objects become ['key' => value] and JSON arrays become [value, ...].

What PHP version is required?

Short array syntax [] requires PHP 5.4 or later, which every supported PHP version has.

How are special characters handled?

Strings are single-quoted, with backslashes and single quotes escaped, so no variable interpolation or escape surprises occur.

Is my JSON uploaded to a server?

No. All JSON tools run entirely in your browser, so your data never leaves your device.

Is there a size limit?

There is no fixed limit. Files of several megabytes work fine; very large files depend on your device's memory.

Do I need an account?

No. Every JSON tool is free and works without signing up.

Last updated:

Related JSON tools