DEVELOPER TOOLS / ONLINE UTILITY

PHP Array to JSON Converter

Turn a simple PHP array literal into formatted JSON for API tests, debugging, and data migration tasks.

FREE ONLINE TOOL

PHP Array to JSON Converter

Runs in your browser
Safe literal parser: this tool does not execute PHP. Variables, function calls, constants, and object expressions are not supported.
OVERVIEW

What is PHP Array to JSON Converter?

PHP arrays are commonly used to organize application data. JSON is a language-independent format used by APIs and JavaScript applications. This converter reads a deliberately limited PHP array-literal syntax and produces JSON without evaluating PHP code.

What can you use it for?

  • Convert a small configuration or sample array into JSON for an API request.
  • Prepare test data for JavaScript or a frontend application.
  • Inspect nested PHP array structures in a more portable format.
  • Create JSON examples from simple PHP array literals.

How to use this tool

  1. Paste a PHP array literal such as ['name' => 'Info4PHP', 'active' => true].
  2. Select Convert to JSON.
  3. Review the formatted JSON output and copy it if it matches your intended data.
  4. If the parser rejects the input, remove variables, function calls, constants, or unsupported PHP expressions.

Example input

This sample contains string keys, scalar values, a boolean, and a nested indexed array.

[
    'name' => 'Info4PHP',
    'version' => 2,
    'active' => true,
    'tags' => ['PHP', 'Tools']
]

Tips and things to know

  • Only literal values are supported: strings, numbers, booleans, null, and nested arrays.
  • Variables, constants, object instances, function calls, and PHP expressions are not evaluated.
  • Associative PHP arrays become JSON objects; sequential numeric arrays become JSON arrays.
  • JSON object keys are strings, so PHP key types may be represented as strings in the output.

Frequently asked questions

Can I paste a complete PHP file?

No. Paste only a PHP array literal, optionally with a simple variable assignment. The converter does not execute PHP source code.

Does it support array() syntax?

The converter supports both short array syntax with square brackets and the array(...) form.

Why are variables or function calls rejected?

The parser accepts only literal values. Evaluating arbitrary PHP expressions would be unsafe and is outside the purpose of this browser-based converter.