Skip to content

PHP Array to JSON Converter

A PHP array literal, var_export or print_r output turned into JSON — nothing executed.

Drop a PHP file here, or click to choose one

Converted on your device — the file is never uploaded

JSON

Quick Tool Overview

The PHP Array to JSON Converter parses PHP array literals, var_export output and print_r output into JSON, keeping types, without executing a single line of PHP.

What it does
Converts a PHP array to JSON
You give it
An array literal, var_export or print_r output
You get back
JSON with the same structure and types
Best for
Reading config files and debugging output
Converters Free, unlimited use No sign-up Runs in your browser

About the PHP Array to JSON Converter

You are debugging, or reading someone else’s config, and what you have is a PHP array — in a config file, dumped by var_export(), or printed by print_r() in a stack trace. Getting it into a form your tools can read normally means running PHP, which you cannot always do and should never do with code you do not trust.

Paste it here and get JSON, with nothing executed. Array literals with [] or array(), var_export output, and print_r output are all read. Single and double-quoted strings, heredocs, integers in hex, octal and binary, floats, booleans and null all keep their types. Arrays with keys 0, 1, 2 … become JSON arrays and any other keys become objects — exactly what json_encode would do. Function calls such as env('DB_HOST', '127.0.0.1') cannot run in a browser, so they resolve to their default argument, and constants become their names.

Key features of the PHP Array to JSON Converter

Three input styles

[] and array() literals, var_export output, and print_r output.

Types kept

Hex, octal and binary integers, floats, booleans, null and heredocs all survive.

Nothing executed

The text is parsed, never run, so an unknown config file is safe to paste.

env() resolved sensibly

A call such as env('DB_HOST', '127.0.0.1') becomes its default value.

Lists stay lists

Keys 0, 1, 2 … become a JSON array — exactly what json_encode would produce.

How to use the PHP Array to JSON Converter

  1. 1

    Paste the PHP array

    A literal, a whole config file with return [ … ];, or print_r output.

  2. 2

    Choose how lists are written

    JSON arrays for sequential keys, or objects throughout.

  3. 3

    Decide about function calls

    Use the default argument, as Laravel config does, or write null.

  4. 4

    Copy or download the JSON

    Indented, minified, or with non-ASCII escaped.

Frequently asked questions

No. The text is parsed, never run, so pasting a config file from an unknown source is safe. That is also why env() and other calls cannot be evaluated.

Reviews of the PHP Array to JSON Converter

What people who use the PHP Array to JSON Converter think of it. Reviews come from visitors and are posted as written.

No ratings yet

Yours would be the first.

  • 5 0 reviews rated 5 stars
  • 4 0 reviews rated 4 stars
  • 3 0 reviews rated 3 stars
  • 2 0 reviews rated 2 stars
  • 1 0 reviews rated 1 star

Write a review

Used this tool? Your rating helps the next person decide.

Your rating

Plain text only — links, email addresses and HTML are not accepted. Your name and review are shown publicly; nothing else is collected. See the privacy policy.

0 reviews

Newest first

No reviews yet

Be the first to rate the PHP Array to JSON Converter. It takes half a minute and no account.

Write the first review

More converters