Use json_encode to write JS variables.