Devkitr

PHP Array to JSON

Live

Convert PHP array syntax to JSON format.

100% Private InstantFree forever
JSON Output

Understanding JSON (JavaScript Object Notation)

PHP arrays are used as the primary data structure in PHP applications for configuration, database results, API responses, and session data. Converting PHP array literals to JSON is necessary when migrating data from PHP to non-PHP systems, creating API documentation from PHP config files, generating frontend configuration from PHP backends, and debugging serialized PHP data. The conversion must handle PHP's unique array features — mixed integer and string keys, short array syntax, and PHP constants.

Parse PHP array syntax and convert it to properly formatted JSON. Supports both short ([]) and legacy (array()) notation, associative and indexed arrays, nested structures, and PHP constants like true, false, and null. Generates valid, formatted JSON output.

The Devkitr PHP Array to JSON Converter parses PHP array literal syntax and outputs equivalent JSON. Paste a PHP array definition to get clean JSON with proper type conversion, key formatting, and structure preservation.

In a typical development workflow, PHP Array to JSON becomes valuable whenever you need to convert php array syntax to json format. Whether you are working on a personal side project, maintaining production applications for a company, or collaborating with a distributed team across time zones, having a reliable browser-based conversion tool eliminates the need to install desktop software, write one-off scripts, or send data to third-party services that may log or retain your information. Since PHP Array to JSON processes everything locally on your device, your data stays private and your workflow stays uninterrupted — open a browser tab, paste your input, get your result.

Key Features

PHP Syntax Parsing

Parses both modern ([]) and legacy (array()) PHP array syntax, including nested arrays and mixed key types.

Constant Resolution

Identifies PHP constants (true, false, null, PHP_INT_MAX) and converts them to their JSON equivalents.

Key Type Handling

Converts PHP integer keys to JSON array positions and string keys to JSON object properties correctly.

Comment Stripping

Removes PHP comments (// and /* */) from the input before conversion, handling commented-out array entries.

How to Use PHP Array to JSON

1

Paste PHP Array

Enter a PHP array expression — $config = [...], return [...], or just the array literal without the assignment.

2

Review JSON Output

Check the JSON structure, verify key names, and confirm that PHP types mapped correctly to JSON types.

3

Handle Edge Cases

Verify that mixed key arrays, PHP constants, and concatenated strings are handled as expected.

4

Copy JSON Result

Copy the JSON for use in API documentation, frontend configuration, or cross-platform data migration.

Use Cases

API Documentation from PHP Config

Convert PHP configuration arrays to JSON for inclusion in API documentation readable by non-PHP developers.

Laravel Config to Frontend

Convert Laravel PHP config arrays to JSON for frontend JavaScript consumption via API endpoints or build-time extraction.

PHP to Node.js Migration

Convert PHP array-based data structures to JSON as part of migrating applications from PHP to Node.js.

Cross-Team Data Sharing

Convert PHP-formatted data to universal JSON for teams working in Python, Java, or JavaScript that cannot read PHP syntax.

Pro Tips

Remove the variable assignment ($config = ) and trailing semicolon before parsing — the converter needs just the array literal.

PHP arrays with only integer keys convert to JSON arrays. Mixed or string-keyed arrays convert to JSON objects.

PHP concatenation operators ('hello' . ' world') cannot be resolved without PHP execution — replace with complete strings before converting.

Nested arrays in PHP ('key' => [1, 2, 3]) map naturally to nested JSON structures.

Common Pitfalls

Including PHP function calls in array values

Fix: JSON cannot represent function calls. Replace env("DB_HOST") with the actual value before converting to JSON.

Expecting PHP class constants to resolve automatically

Fix: Constants like MyClass::STATUS_ACTIVE need to be replaced with their actual values — the converter cannot execute PHP code.

Not handling PHP heredoc/nowdoc string syntax

Fix: PHP heredoc (<<<EOT) and nowdoc (<<<'EOT') strings need to be replaced with regular quoted strings before JSON conversion.

Frequently Asked Questions

QDoes it support legacy array() syntax?

Yes. Both modern short array syntax ([]) and legacy array() notation are supported for parsing.

QWhat about PHP constants?

PHP constants like true, false, null, and numeric values are correctly mapped to their JSON equivalents.

QCan it handle complex nested arrays?

Yes. Deeply nested associative and indexed arrays are fully supported and converted to proper JSON structure.

Related Articles

Related Tools

You Might Also Need

More Converters