Converters

PHP to JSON Converter

Paste a PHP array literal — either the array() syntax or the short [] syntax — and get JSON back. The converter handles nested arrays, string and integer keys, quoted and unquoted strings, and PHP-specific syntax like => for key-value pairs. Useful when migrating PHP code to a JSON-based configuration or JavaScript application.

PHP to JSON — Convert a PHP array literal to JSON

What it does

  • Converts PHP array() syntax to JSON
  • Converts PHP short array syntax ([]) to JSON
  • Handles nested arrays of any depth
  • Parses string keys (with single or double quotes) and integer keys
  • Handles PHP string concatenation in values (basic cases)

Use cases

  • Migrating PHP configuration arrays to JSON for a JavaScript application
  • Converting PHP data structures to JSON for an API response
  • Transforming PHP test data to JSON for cross-language testing
  • Inspecting a PHP array literal as structured JSON

How it works

1

Paste your PHP array literal into the input pane

2

The parser handles array(), [], =>, and quoting

3

The structure is converted to JSON and displayed in the output pane

4

Copy the JSON for use in your application

Frequently asked questions

1Does it handle both array() and [] syntax?

Yes. The parser supports both the traditional array() syntax and the short [] syntax introduced in PHP 5.4. You can mix them in the same input.

2What about PHP constants and function calls?

The converter handles literal values (strings, numbers, booleans, null, arrays). PHP constants (like PHP_EOL) and function calls are not evaluated — they're treated as strings.

3Can it handle PHP objects?

This tool focuses on array literals. PHP objects instantiated with new ClassName() are not supported. For serialized PHP objects, use the PHP Unserializer tool instead.

Related tools

Use PHP to JSON offline in Devinity

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

Download Devinity →