Developer tool

PHP Array ↔ JSON Converter

Convert between JSON and PHP array literals using a restricted parser—no eval and no variable execution.

How it works

What it does

This converter translates JSON documents into PHP array literal syntax and, in the reverse direction, parses a restricted subset of PHP array literals into JSON. It is designed for config snippets, fixture data, and API payload prototyping.

When to use it

  • Turn an API JSON sample into a PHP fixture array
  • Export a PHP config array shape to JSON for another service
  • Validate that a structure round-trips without surprise type changes

How input is processed safely

PHP→JSON uses a restricted tokenizer: no variable interpolation, no function calls, no constants lookup beyond safe literals, and no eval. JSON→PHP builds literals from decoded JSON only. Unsupported PHP expressions are rejected instead of being executed.

Examples

  • JSON object with nested arrays → short PHP array syntax
  • List of scalars → JSON array for a frontend mock
  • Rejecting ['x' => getenv('SECRET')] because calls are not allowed

Common mistakes

  • Pasting full PHP files with classes and expecting conversion
  • Assuming PHP true/false/null case variants always survive round-trips identically
  • Forgetting JSON objects become associative arrays in PHP decoding conventions

JSON and PHP arrays disagree on several edges: object vs empty array ambiguity, numeric string keys, and Unicode escaping. The converter surfaces those edges instead of silently inventing values. If a PHP literal includes expressions, variables, or function calls, conversion is rejected because those forms cannot be represented safely without execution.

For configuration that must remain PHP-native (class constants, env helpers), keep the source as PHP and export only the static subset you need. For cross-language interchange, prefer JSON as the long-term storage format and generate PHP fixtures from it.

Pretty-printed output is intentional for review. If you need compact JSON for transport, pipe the JSON result through the site’s JSON formatter minify mode after conversion.

Privacy note

Configs often contain DSN passwords and tokens. Redact them. The converter does not need real secrets to demonstrate structure.

Run in browser

AJAX processing only. No remote PHP execution sandbox. Results are not indexed.

Inputs are processed for this request only and are not stored in analytics. Object unserialize and arbitrary PHP execution are blocked.

Safety notes

  • Submitted tool contents are not written to analytics or search logs.
  • This site never evaluates arbitrary PHP from the browser.
  • Generated configs are starting points—validate on a staging host before production.