Skip to content

Developer tools

PHP json_decode & json_encode Online

Paste JSON to see exactly what json_decode() gives you, as PHP array code or print_r() output. Or paste a PHP array and get json_encode() output with the flags you choose.

Converted in your browser. Nothing is uploaded.


                
                
The result appears here as you type.

How to use the PHP json_decode & json_encode Online

  1. 1

    Choose json_decode (JSON → PHP) or json_encode (PHP → JSON) and paste your input. It converts as you type.

  2. 2

    For decoding, choose arrays or stdClass objects and PHP code or print_r(). For encoding, tick the JSON_* flags you use.

  3. 3

    Copy or download the result, or Swap to convert it back. The line at the bottom is the matching PHP code.

Frequently asked questions

What does the second argument of json_decode do?

json_decode($json, true) returns associative arrays. Without it (or with false), JSON objects become stdClass objects, accessed as $data->name instead of $data['name'].

Why does json_encode turn my array into an object?

A PHP array becomes a JSON list only when its keys are 0, 1, 2, … in order. Any other keys (strings, gaps, a different order) give a JSON object. Use array_values() to get a list.

Why are slashes and accents escaped?

By default json_encode writes / as \/ and non-ASCII characters as \u00e9. Add JSON_UNESCAPED_SLASHES and JSON_UNESCAPED_UNICODE to keep them as they are.

What PHP code can I paste?

Arrays in [] or array() syntax, strings, numbers, true, false and null, nested as deep as you like. A full statement like $data = [...]; or return [...]; works too. Variables, constants and function calls can't be evaluated in the browser.

Get new articles in your inbox

Practical tutorials and deep dives, about once a week. No spam, unsubscribe anytime.

Privacy policy

Add DEV Talk to your Home Screen

  1. 1 Tap the Share button in Safari's toolbar.
  2. 2 Scroll down and tap Add to Home Screen.
  3. 3 Tap Add. Open it from the Home Screen to read like an app and to turn on notifications with the bell.

We use cookies to improve your experience and analyze traffic. By continuing, you agree to our Privacy Policy.