For encoding JSON in PHP, json_encode () function is used. This function returns the JSON representation of a value on success or false on failure.