Back to Tools

JSON to PHP Array Converter

Convert JSON to PHP array online with [] or array() output and nested data support

Loading...

How to Convert JSON to PHP Array

  1. 1

    Paste JSON

    Copy your JSON data and paste it into the input field on the left.

  2. 2

    Select Options

    Choose conversion options such as sorting keys alphabetically or flagging associative arrays.

  3. 3

    Copy Result

    The PHP array appears instantly on the right. Click copy to use it in your project.

Features Overview

Bidirectional converter between JSON and PHP arrays. Convert JSON payloads to PSR-12 compliant PHP code, or parse PHP arrays back to JSON format.

Tool Description

Free JSON to PHP array converter online. Paste JSON and generate PHP array code with short [] or long array() syntax, nested objects, associative arrays, and Laravel or Symfony-ready examples. You can also turn PHP arrays back into JSON in the browser with no uploads.

Capabilities Checklist

  • Bidirectional conversion: JSON to PHP array and PHP array to JSON.
  • Parse JSON instantly with syntax validation and precise error locations.
  • Generate PSR-12 compliant PHP arrays with proper indentation and trailing commas.
  • Syntax highlighting that adapts to light or dark mode.
  • Sort keys alphabetically and detect associative arrays automatically.

Related Tools

Related Guides

Frequently Asked Questions

How do I convert JSON to a PHP array?
Paste your JSON data into the input field with 'JSON → PHP' mode selected. The tool will automatically convert it to a PHP array using short array syntax with PSR-12 formatting. You can then copy the result and use it directly in your PHP code.
How do I convert a PHP array to JSON?
Click 'PHP → JSON' to switch conversion direction, then paste your PHP array code. The tool supports both short array syntax ['key' => 'value'] and will output properly formatted JSON that you can use in APIs, config files, or JavaScript applications.
What is json_encode() in PHP?
json_encode() is a built-in PHP function that converts PHP values (arrays, objects, strings, etc.) to JSON format. For example: json_encode(['name' => 'John', 'age' => 30]) returns '{"name":"John","age":30}'. This tool performs the same conversion but adds formatting for readability.
What is json_decode() in PHP?
json_decode() is a PHP function that parses JSON strings and converts them to PHP values. Use json_decode($json, true) to get an associative array, or json_decode($json) to get an object. Our tool's JSON → PHP mode simulates this conversion with readable output.
What's the difference between indexed and associative arrays in PHP?
Indexed arrays use numeric keys (0, 1, 2...) like [1, 2, 3], while associative arrays use string keys like ['name' => 'John', 'age' => 30]. In JSON, indexed arrays become JSON arrays [], and associative arrays become JSON objects {}. This tool automatically detects and handles both types.
Does this tool support nested arrays and objects?
Yes, the converter fully supports deeply nested structures. You can convert complex JSON with multiple levels of nesting, arrays of objects, and mixed data types. The PHP output maintains proper indentation for readability.
How are special characters handled in the conversion?
Special characters are properly escaped during conversion. In PHP output, single quotes and backslashes are escaped. In JSON output, Unicode characters, quotes, and control characters are escaped according to JSON specification. This ensures the output is valid and safe to use.
What is PSR-12 formatting?
PSR-12 is a PHP coding style guide that defines formatting rules including 4-space indentation, trailing commas in multi-line arrays, and consistent spacing. Our tool generates PHP arrays that follow these standards, making the output ready to paste into professional PHP projects.
What is the difference between short syntax [] and long syntax array() in PHP?
Short array syntax [] has been supported since PHP 5.4 and is more concise — it's the recommended way for modern PHP projects. Long syntax array() is compatible with all PHP versions and more commonly seen in legacy projects. This tool supports both syntaxes and you can switch between them in the conversion options.
How do I use the converted PHP array in Laravel or Symfony?
This tool provides framework snippet templates for both Laravel config and Symfony parameters. After conversion, click the framework snippets section and select your framework to generate ready-to-use configuration code, such as a Laravel config file or the PHP array equivalent of Symfony's parameters.yaml.
Does this tool upload my data to a server?
No. All conversions happen entirely in your browser — your JSON data and PHP code are never sent to any server. This ensures complete privacy for your code and data. You can even use this tool while offline.