JSON to PHP Array Converter

Convert JSON into a PHP array using short or long array syntax.

The JSON to PHP Array Converter turns a JSON payload into a formatted PHP array literal you can paste directly into a script, configuration file, or test fixture. It walks the structure recursively, mapping objects to associative arrays and JSON arrays to indexed arrays, and it indents everything cleanly so the result is easy to read and maintain rather than a single dense line.

You can choose between the modern short array syntax using square brackets and the classic long syntax using the array keyword, so the output matches your codebase and PHP version conventions. JSON true, false, and null are converted to PHP true, false, and null, string keys and values are quoted and escaped correctly, and numbers are emitted as-is, giving you code that is valid the moment you paste it.

The converter runs entirely in your browser, so the JSON you paste is never uploaded or stored anywhere. That keeps API responses, internal configuration, and sample data private while you work. It is free with no sign-up and produces results instantly, so you can adjust your sample and regenerate the PHP array as many times as you need.

Features

  • Converts JSON objects to associative arrays and JSON arrays to indexed arrays.
  • Offers modern short bracket syntax or classic array() long syntax to match your code.
  • Maps JSON true, false and null to PHP true, false and null automatically.
  • Escapes single-quoted string keys and values so special characters never break output.
  • Indents nested structures cleanly for readable, maintainable array literals.
  • Assigns the array to a named variable you can rename to fit your script.
  • Runs fully in your browser with instant copy or download of the result.

How to use JSON to PHP Array Converter

  1. Paste a JSON object or array into the input box.
  2. Choose short bracket syntax or long array() syntax.
  3. Set the variable name if you want something other than the default.
  4. Review the generated PHP array and confirm the structure looks right.
  5. Copy the code into your PHP file, or download it as a text file.
  6. Adjust your JSON sample and regenerate whenever the data changes.

Benefits

  • PHP developers embed configuration and fixtures without rewriting JSON by hand.
  • Short or long syntax keeps generated code consistent with legacy or modern projects.
  • Correct escaping avoids subtle bugs from quotes and backslashes in data.
  • Clean indentation makes large arrays easy to scan and edit in code review.
  • Instant regeneration speeds up iterating on data-driven configuration.
  • Local processing keeps private payloads and secrets off any server.

PHP arrays are flexible enough to represent both JSON objects and arrays, which is why this converter maps objects to associative arrays keyed by their property names and JSON arrays to plain indexed arrays. This mirrors what you get from json_decode with associative mode enabled, so the generated literal is a natural fit if you are replacing a runtime decode with a static array baked into your code.

String values and keys are wrapped in single quotes, which in PHP means only backslashes and single quotes need escaping, keeping the output tidy. If your data includes values that should be treated as specific PHP types, such as integers stored as strings, review those fields after pasting. The short array syntax requires PHP 5.4 or later, so choose the long syntax if you must support very old runtimes.

Because all processing happens locally in your browser, there is no upload and no size limit beyond your device memory, so large responses convert instantly and privately. Treat the generated array as a ready-to-use starting point that you can rename, reformat, or wrap in a return statement for a configuration file exactly as your project requires.

Frequently asked questions

Related tools