The json_encode function takes a PHP array or object and returns a string of JSON.

    
    $numbers = array('a' => 1, 'b' => 2, 'c' => 3, 'd' => 4, 'e' => 5);

    $numbers_encoded = json_encode($numbers);

    echo $numbers_encoded;
    // {"a":1,"b":2,"c":3,"d":4,"e":5}