JSON to PHP Array

JSON Tools

How to use the JSON to PHP Array

Convert JSON to PHP in one click:

1

Paste your JSON

Paste any valid JSON object or array into the input panel.

2

Set variable name

Enter a PHP variable name — the output will be prefixed with $yourName = automatically.

3

Click Convert

Get PHP array syntax using short array notation [] (PHP 5.4+) with proper string escaping.

4

Copy into your PHP file

Copy the output and paste it directly into your PHP file — it's ready to use.


When to use this tool

Use this whenever you need PHP array syntax from JSON data:

  • Converting an API response to a hardcoded PHP array in a Laravel or WordPress project
  • Creating PHP config or settings arrays from JSON configuration files
  • Building PHP test fixtures from real JSON API responses
  • Converting JSON translation files to PHP array format for Laravel lang files
  • Seeding a database with static PHP array data originally sourced from JSON
  • Quickly prototyping with hardcoded PHP data during development without a live API

Frequently asked questions

Q:Does it use short [] or long array() syntax?
The tool always uses modern short [] syntax (PHP 5.4+), which is the current standard. The old array() syntax is not generated.
Q:How are JSON booleans and null handled?
JSON true becomes PHP true, false becomes false, and null becomes null — all matching PHP's native keyword literals exactly.
Q:How are strings escaped?
All strings are wrapped in single quotes. Single quotes and backslashes inside string values are automatically escaped (\' and \\), so the output is always valid PHP.
Q:Are nested objects and arrays supported?
Yes. Nested JSON objects become nested PHP associative arrays, and JSON arrays become sequential PHP arrays — both using [] notation at every level.
Q:Can I use this with Laravel, WordPress, or Symfony?
Yes. The output is plain PHP array syntax compatible with any PHP 5.4+ framework. It's especially useful for Laravel lang files, WordPress options arrays, and Symfony parameter configs.
Q:Can I convert PHP arrays back to JSON?
In PHP, use json_encode($array, JSON_PRETTY_PRINT) to convert back to JSON. On this site, any of our JSON tools can process JSON you've encoded from PHP.