JSON ↔ PHP Array Converter

Convert instantly in your browser. Max file size: 100 MB. Nothing is stored on the server.

Free: 6 / 6 left today • 100 MB
Input
Drop file to upload
Output

Need to convert PHP to JSON online without writing a throwaway script? This free PHP to JSON converter turns a PHP array into valid JSON in one click, and it works the other way too: paste JSON and get a clean JSON array to PHP array back, ready for your project. It can also read PHP serialized data (the string produced by serialize()) and show it as readable JSON, which is handy when you are debugging WordPress options, post meta or WooCommerce data stored in the database.

PHP array to JSON converter diagramA PHP array on the left is converted into JSON on the right, and JSON can be converted back into a PHP array.PHP array$user = [‘name’=>‘Mina’,‘age’=>28,‘tags’=> [‘php’,‘wp’]];CONVERTjson_encode()json_decode()JSON{“name”:“Mina”,“age”:28,“tags”: [“php”,“wp”]}
PHP array to JSON and JSON to PHP array, both directions in one tool.

What Is a PHP to JSON Converter?

A PHP to JSON converter is a tool that changes data written in PHP syntax into JSON (JavaScript Object Notation), the text format most APIs, JavaScript front ends and modern databases expect. PHP stores structured data in arrays and objects. JSON stores the same ideas as arrays, objects, strings, numbers, booleans and null. Because the two formats look similar but follow different rules (=> versus :, single quotes versus double quotes, trailing commas allowed in PHP but not in JSON), converting by hand is slow and easy to get wrong.

Inside PHP, the built-in function json_encode() does this job. An online converter gives you the same result in your browser, so you can check an array, share a sample with a teammate or prepare a test payload without opening an editor or running a script. The reverse direction, JSON to array in PHP, relies on json_decode(), and the tool prints the matching PHP array so you can paste it straight into your code.

How to Convert PHP Array to JSON Online

You do not need to install anything. Follow these steps:

Three steps to convert PHP array to JSONStep one paste your PHP array. Step two choose the conversion direction and format. Step three copy or download the result.1Paste your dataPHP array, JSON or serialized2Pick direction and stylePretty or minified output3Copy or downloadUse it in your project
Convert PHP to JSON online in three quick steps.
  1. Paste your input. Add a PHP array (short [] or classic array() syntax), a JSON string, or a PHP serialized string into the input box.
  2. Choose the direction and output style. Select PHP to JSON or JSON to PHP, then pick pretty (indented) or compact (minified) output.
  3. Convert and copy. Review the result, copy it or download it, then drop it into your script, API client or config file.

Here is a typical example. This PHP array:

$user = [
    'name'   => 'Mina',
    'age'    => 28,
    'active' => true,
    'skills' => ['PHP', 'WordPress', 'WooCommerce'],
];

becomes this JSON:

{
    "name": "Mina",
    "age": 28,
    "active": true,
    "skills": ["PHP", "WordPress", "WooCommerce"]
}

Notice that the associative array turned into a JSON object, while the indexed skills list stayed an array. That is the core rule of PHP array to JSON conversion, and the table further down shows every type mapping.

JSON to PHP Array: How It Works

Going the other direction is just as common. You may receive a JSON response from a REST API, a payment gateway or a WordPress endpoint and want a PHP array you can read, edit or use as test data. Paste the JSON and the tool prints the array in PHP syntax. A JSON object to PHP conversion becomes an associative array with key => value pairs, and a JSON array becomes a plain indexed array.

In your own code, the same result comes from one function call:

$json  = '{"name":"Mina","age":28}';
$array = json_decode($json, true); // true = associative array
echo $array['name']; // Mina
Tip: if you leave out the second argument, json_decode() returns a stdClass object and you read values with $data->name instead of $data['name']. Pick one style and stay consistent across your project.

PHP Serialized Data to JSON Converter

PHP’s function stores arrays and objects as a compact string. WordPress uses it widely: theme options, widget settings, plugin settings and a lot of WooCommerce post meta live in the database in serialized form. A raw serialized value is hard to read:

a:2:{s:4:"name";s:4:"Mina";s:3:"age";i:28;}

Run it through the PHP serialized data to JSON converter and you get:

{
    "name": "Mina",
    "age": 28
}

This makes it simple to inspect options exported from wp_options, compare two settings exports, or migrate configuration to a system that expects JSON. If you work with a database export, you can then tidy the output with our JSON formatter and beautifier.

Security note: never call unserialize() on data from an untrusted source, because crafted strings can trigger object injection. When you only need to read the content, converting it to JSON for inspection is the safer habit, and for new data, store JSON instead of serialized strings.

Parse JSON in PHP: json_decode() Explained

To parse JSON in PHP, use json_decode() and always check for errors. A single stray comma makes the whole string invalid.

$data = json_decode($json, true);

if (json_last_error() !== JSON_ERROR_NONE) {
    echo 'JSON error: ' . json_last_error_msg();
}

On PHP 7.3 and later you can also pass JSON_THROW_ON_ERROR and catch a JsonException, which keeps error handling in one place. For the full syntax rules, see the official or the overview at .

When you want the other direction with nice formatting, combine flags:

echo json_encode($user, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE);

How PHP Types Map to JSON

PHP to JSON data type mapping chartAssociative array becomes JSON object, indexed array becomes JSON array, string stays string, int and float become number, true and false become boolean, null stays null.PHPJSON[‘a’ => 1]{“a”: 1}associative array to object[1, 2, 3][1, 2, 3]indexed array to array‘text’“text”string to string42 / 3.1442 / 3.14int, float to numbertrue / nulltrue / nullbool, null stay the same
How PHP data types map to JSON when you convert a PHP array to JSON.
PHP JSON Watch out for
['a' => 1] {"a":1} String keys always make an object.
[1, 2, 3] [1,2,3] Keys 0 to n-1 in order make a list.
[1 => 'a', 2 => 'b'] {"1":"a","2":"b"} Gaps in numeric keys turn the array into an object.
[] [] An empty PHP array is never {}.
1.0 1 Use JSON_PRESERVE_ZERO_FRACTION to keep 1.0.
"café / é" "caf\u00e9 \/ \u00e9" Unicode and slashes are escaped by default; add flags to keep them readable.

Benefits of Using a PHP to JSON Converter

Wondering why developers keep a converter bookmarked when json_encode() exists? These are the practical reasons:

Speed

Instant results

Check an array or JSON snippet in seconds without creating a file, running a script or restarting a local server.

Accuracy

Valid output every time

No missing quotes, no trailing commas, no mixed up => and :. The result is ready for APIs and validators.

Debugging

Easier debugging

Turn serialized strings and nested arrays into readable, indented JSON so you can spot wrong values quickly.

Two-way conversion

Both directions

Go from PHP to JSON and from JSON to PHP in one place, instead of juggling two separate tools.

Integration

Faster integrations

Prepare test payloads for REST APIs, JavaScript apps, WordPress and WooCommerce endpoints without extra boilerplate.

Privacy

No signup needed

Open the page, paste, convert. There is no account, no install and no plugin to maintain.

Learning

Learn by example

Seeing input and output side by side is the quickest way to understand how arrays, objects and serialized strings relate.

Real-world use cases

  • Sending PHP data to a JavaScript front end or a mobile app through an API.
  • Reading WordPress options and WooCommerce meta stored as serialized strings.
  • Turning an API response into a PHP array for unit tests and fixtures.
  • Migrating configuration between PHP projects and JSON based systems.
  • Documenting code with clean, validated JSON examples.

Common PHP to JSON Conversion Mistakes

  • Trailing commas. PHP accepts [1, 2, 3,], JSON does not. A good converter removes them; json_decode() returns NULL if you leave one in a JSON string.
  • Single quotes. JSON strings must use double quotes. Quotes inside values need careful escaping.
  • Expecting {} from an empty array. PHP encodes [] as []. Cast to (object) or use new stdClass when you need an empty object.
  • Invalid UTF-8. json_encode() fails on broken character encoding. Clean the string first or use JSON_INVALID_UTF8_SUBSTITUTE.
  • Very large integers. Numbers above PHP_INT_MAX decode as floats and can lose precision.
  • Pasting PHP code with variables or functions. A converter reads data, not logic. Remove $var = prefixes, function calls and comments before converting if you see an error.

After converting, tidy the result with the JSON minify and beautify formatter, and if your PHP source is messy, run it through the PHP beautifier first.

Working with several data formats? These free tools pair well with the PHP to JSON converter:

Browse the full collection on the Athemeart free tools page.

Frequently Asked Questions

How do I convert a PHP array to JSON?

Paste the array into the converter, select PHP to JSON and press convert. In code, call json_encode($array). Associative arrays become JSON objects and indexed arrays become JSON arrays.

How do I convert JSON to an array in PHP?

Use json_decode($json, true). The second argument tells PHP to return an associative array instead of an object. You can also paste your JSON into this tool to get the PHP array syntax directly.

How do I convert a JSON object to PHP?

A JSON object becomes an associative array when you pass true to json_decode(), or a stdClass object when you do not. Choose the array form if you want to access values with $data['key'].

Can this tool convert PHP serialized data to JSON?

Yes. Paste the string created by serialize(), such as a WordPress option value, and the converter returns readable JSON you can inspect or reuse.

What is the difference between serialize() and json_encode()?

serialize() is PHP specific and keeps PHP types and class names, while json_encode() produces a language neutral text format that JavaScript, Python and most APIs can read. JSON is the better choice for data you plan to share or store long term.

Why does json_decode() return NULL?

The most common causes are a trailing comma, single quotes, an unescaped character or invalid UTF-8. Check json_last_error_msg() for the exact reason, or paste the string into a JSON formatter to find the line.

Is it safe to paste my data into an online converter?

Avoid pasting passwords, API secrets or private customer data into any online tool. For sensitive content, convert locally with json_encode() and json_decode() on your own machine.

Does this tool support short array syntax and array()?

Yes. Both ['a' => 1] and array('a' => 1) are supported when converting between PHP and JSON.

Is the PHP to JSON converter free?

Yes. It is free to use, needs no registration and works on desktop and mobile browsers.

Ready to try it? Scroll up, paste your PHP array, JSON or serialized string, and convert it in one click.