BYTETOOLS

PHP Array to JSON Converter

Convert PHP array literals to JSON online. Parses array() and [] syntax, => keys, nesting and quotes, and outputs lists as real JSON arrays.

What is the PHP Array to JSON Converter?

The ByteTools PHP Array to JSON Converter parses PHP array literals — both the classic array( … ) syntax and the short [ … ] form — and converts them to clean JSON.

  • Supports array( … ) and short [ … ] syntax, nested to any depth
  • PHP key semantics: sequential integer keys become JSON arrays
  • Correct single-quote vs double-quote escape handling
  • Comments (//, #, /* */) and trailing commas accepted
  • Nothing is executed — pure parsing with clear error positions
  • 100% private — code never leaves your browser

How to use the PHP Array to JSON Converter

  1. 1

    Paste a PHP array literal — a $config = wrapper or <?php tag is fine.

  2. 2

    Choose the output indentation.

  3. 3

    Click Convert to JSON.

  4. 4

    Copy the JSON or download it as a .json file.

About the PHP Array to JSON Converter

The ByteTools PHP Array to JSON Converter parses PHP array literals — both the classic array( … ) syntax and the short [ … ] form — and converts them to clean JSON. It understands => key arrows, single- and double-quoted strings with their different escape rules, numbers, true/false/null, nested arrays and trailing commas.

It follows PHP's own semantics for keys: arrays with sequential integer keys starting at 0 become JSON arrays, everything else becomes a JSON object, numeric-string keys are treated as integers, and duplicate keys resolve to the last value — the same result json_encode would give. A leading $var = assignment or <?php tag is stripped automatically.

Parsing is done by a hand-written tokenizer running 100% locally in your browser; no PHP code is ever executed and nothing you paste is uploaded or stored.

Frequently asked questions

How do I convert a PHP array to JSON online?

Paste the array literal, pick an indentation and click Convert to JSON. The tool parses the PHP syntax directly — including => keys and nesting — and prints the equivalent JSON, matching what json_encode would produce.

When does a PHP array become a JSON array vs an object?

If the keys are exactly 0, 1, 2 … in order (including arrays with no explicit keys), the output is a JSON array. Any string key, gap or out-of-order index makes it a JSON object — the same rule PHP's json_encode uses.

Are single-quoted and double-quoted strings treated differently?

Yes, just like in PHP. Single-quoted strings only unescape \' and \\, while double-quoted strings process \n, \t, \x hex, \u{…} unicode and other escapes. That keeps the converted values byte-accurate.

Does the tool run my PHP code?

No. It is a parser, not an interpreter — variables, function calls and expressions other than literals are rejected with an error message. Only literal arrays and scalar values are converted.

Is anything uploaded to a server?

No. The conversion happens entirely in your browser with JavaScript, so config files and seed data stay private.

Related tools