PHP JSON Encode Example

Convert a PHP array to JSON with json_encode(). Edit the code below and press Run to execute it with real PHP in your browser.

Code Editor
Output
{"name":"John","age":30,"skills":["PHP","JavaScript","Python"]}
{
    "name": "John",
    "age": 30,
    "skills": [
        "PHP",
        "JavaScript",
        "Python"
    ]
}

How this json encode example works

Associative arrays become JSON objects and lists become JSON arrays. JSON_PRETTY_PRINT adds indentation. See json_encode() for flags and for why it can return false.