Rename row field when generating json file with php
<p>i'm generating a json file using php and a odbc connection. My query is translated well to the json file. </p>

<p>This is my sql query:</p>

<pre><code>SELECT  Date1, Nett FROM database WHERE Date1 BETWEEN '$bdate' AND '$edate' AND String13='$sr' ORDER BY Date1 desc;
</code></pre>

<p>This will be in json: </p>

<pre><code>{"Date1":"2015-10-09 00:00:00.000","Nett":"20860.0"}
</code></pre>

<p>But i want that the output is </p>

<pre><code>{"date":"2015-10-09","value":20860}
</code></pre>

<p>So basically i want that the rows "Date1" and "Nett" 
automatically be translated to "date" and "value" in the json file.
optional also just the date and not datetime. </p>

<p>I want to rename this field because my chart is feeded by json file that needs the field date and value.</p>

<p>This is what i have so far.. </p>

<pre><code>//json
$json_file_name = "uniwin/json/File_export.json";
$json_file_name = str_replace(" ", "_", $json_file_name);

// Open output file
$fp = fopen($json_file_name, 'w');

// Write JSON list start    
fwrite($fp, '[');

// Write each object as a row
$isFirstRow = true;
while ($row = odbc_fetch_array($json)) {

    if (!$isFirstRow) {
        fwrite($fp, ',');
    } else {
        $isFirstRow = false;
    }

    fwrite($fp, json_encode($row));
}

// Write JSON list end
fwrite($fp, ']');

// Close file and MySQL connection
fclose($fp);
</code></pre>

<p>}</p>