[Solved] how to insert a new field in a json file


You can achieve output this way..

$data="{
    "AAL": {
        "id": "32313",
        "airport_name": "Aalborg",
        "latitude": "57.1",
        "longitude": "9.85",
        "timezone": "2",
        "dst_indicator": "E",
        "city": "Aalborg",
        "country": "Denmark",
        "country_code": "DK",
        "region": "TC1",
        "listing_display": "true",
        "pseudonyms": ""
    },
    "AAR": {
        "id": "32314",
        "airport_name": "Tirstrup",
        "latitude": "56.15",
        "longitude": "10.2167",
        "timezone": "2",
        "dst_indicator": "E",
        "city": "Aarhus",
        "country": "Denmark",
        "country_code": "DK",
        "region": "TC1",
        "listing_display": "true",
        "pseudonyms": ""
    }
}";

$arrData  =  json_decode($data,true);
foreach($arrData as $key=>$val){
    $arrData[$key]['station_code']=$key;
}

echo json_encode($arrData);
exit;

solved how to insert a new field in a json file