JSON to PHP Array

Convert JSON into ready-to-paste PHP array syntax — short [] or classic array(), with your preferred indentation.

Tool input is processed locally in your browser and is not submitted to CodeNimbleTools. Avoid pasting production secrets into any device or website you do not fully trust.

PHP array

  

About this tool

Config files, seeders and fixtures often start life as JSON but need to live in PHP. This converter turns any JSON document into valid PHP array code — modern short syntax or classic array(), with 2-space, 4-space or tab indentation.

Strings are safely single-quoted and escaped, so the output drops straight into your project.

How to use it

  1. Paste JSON into the input.
  2. Pick short [] or long array() syntax.
  3. Choose indentation and whether to include $data =.
  4. Copy or download as a .php file.

Useful ways to apply it

  • Converting a JSON config into a PHP config file.
  • Building Laravel/Symfony seed data from API responses.
  • Turning fixture JSON into PHPUnit test arrays.
  • Migrating settings from a JS project to a PHP project.

Worked example

Example input

{"site":"CodeNimbleTools","features":["fast","private"],"active":true}

Expected output

$data = ['site' => 'CodeNimbleTools', 'features' => ['fast', 'private'], 'active' => true];

Edge cases to check

  • JSON numbers do not encode PHP-specific integer/float range intent.
  • Object keys and string values need PHP string escaping.
  • A generated PHP literal does not validate an external payload before runtime use.

Known limitations

The converter maps JSON values to PHP array syntax; it does not create typed DTOs, classes, validators or application-specific hydration logic.

How this tool was reviewed

Reviewed with nested arrays/objects, quotes/backslashes, null, booleans and short/long array syntax.

Last reviewed: September 3, 2026 · Maintainer: William

Standards and technical references

Frequently asked questions

Are booleans and null converted correctly?
Yes — true, false and null become PHP true, false and null literals, not strings.
How are special characters escaped?
Output uses single-quoted PHP strings, so only backslashes and single quotes are escaped. Everything else stays literal.
Can it handle deeply nested JSON?
Nested objects and arrays are supported, but practical depth is limited by browser memory and JavaScript runtime behavior. Test unusually deep production payloads before relying on generated output.

Privacy

Tool input is processed locally in your browser and is not submitted to CodeNimbleTools. Avoid pasting production secrets into any device or website you do not fully trust.