Connor Bishop Connor Bishop - 5 months ago 6
JSON Question

Echoing JSON Data in php

Im trying to echo some JSON Data. The problem is the data contains variables but my code isn't putting the variables into the string.
Heres my code:

$status = $row['Status'];
$priority = $row['Priority'];
echo '{"status":"$status","priority":"$priority"}' ;


this php is echoing

{"status":"$status","priority":"$priority"}


when I need to echo

{"status":"Completed","priority":"High"}


for example. How can I fix this?

Answer

Just use json_encode function

echo json_encode($row);