Converters

JSON to PHP Converter

Paste JSON and get a PHP array literal back. The converter handles nested objects and arrays, proper string quoting with escaping, and outputs either the traditional array() syntax or the short [] syntax. Useful for generating PHP configuration files or test data from JSON.

JSON to PHP — Convert JSON to a PHP array literal

What it does

  • Converts JSON objects to PHP associative arrays
  • Converts JSON arrays to PHP indexed arrays
  • Handles nested structures of any depth
  • Properly escapes strings with single or double quotes
  • Choice of array() or [] syntax for output

Use cases

  • Generating PHP configuration files from JSON data
  • Creating PHP test fixtures from JSON sample data
  • Converting API responses to PHP array syntax for documentation
  • Migrating JSON configuration to a PHP application

How it works

1

Paste your JSON into the input pane

2

Choose array() or [] output syntax

3

The tool converts the JSON structure to a PHP array literal

4

Copy the PHP code into your project

Frequently asked questions

1Does it handle nested objects and arrays?

Yes. JSON objects become PHP associative arrays (['key' => 'value']) and JSON arrays become PHP indexed arrays (['value1', 'value2']). Nesting is preserved at all depths.

2How are strings quoted?

The converter uses single quotes for strings by default, which is the most common PHP convention. Single quotes inside strings are escaped with \. This avoids issues with variable interpolation that double quotes would introduce.

3Can I use this with the PHP Serializer tool?

The PHP Serializer produces PHP serialize() format (a:2:{s:4:...}), which is different from a PHP array literal. This tool generates readable PHP array syntax for use in source code, while the serializer generates the binary-safe format for storage.

Related tools

Use JSON to PHP offline in Devinity

All 95 tools run locally on your Mac. No internet required, no data sent to servers.

Download Devinity →