The below php takes my csv file and outputs to JSON file.
<?php
echo "<h2>Uploading....</h2>";
$fh = fopen("assets/files/locationsCSV.csv", "r");
$csvData = array();
while (($row = fgetcsv($fh, 0, ",")) !== FALSE) {
$csvData[] = $row;
}
// echo json_encode($csvData);
file_put_contents("assets/files/locationsCSV.json",json_encode($csvData))
?>
the JSON in my json file outputs like this, below: Current Output:
["Zipcode","City","Primary State","SS","County"], # only prints once
["24553","","Virginia","49050","Appomattox"], # then just this
["24553","","Virginia","49140","Buckingham"], # etc
How could I get it to output like this/reformatted with zipcode column as object header?
Desired JSON output:
{
ZipCode: 24553, {
City: ,
Primary State: Virginia,
SS: 49050,
County: Appomattox
}
ZipCode: 24553, {a typo? Because it's not valid JSON :)