i have a json. i need to copy the content of "data" if provider is "AXIS DATA" to a new json file. How?
what i have tried is
first i convert with json.parse and searching it with for loop.
this is my code so far
var hasilsearching = {};
var hasildata = JSON.parse( FIRST JSON );
for (var i=0 ; i < hasildata.data.length ; i++){
if (hasildata.data[i].provider == "AXIS DATA") {
hasilsearching = hasildata.data[i];
}
}
but not what i expected. I know inside the if() is the problem. but i dont know.
this is my json file
{
"errNumber": "0",
"userID": "EKL0003097",
"data": [
{
"code": "BXD1",
"price": "15000.00",
"name": "Voucher Axis Aigo 1GB 24J 30H",
"ep": "770",
"isActive": "Active",
"type": "KUOTA",
"provider": "AXIS DATA"
},
{
"code": "BXD2",
"price": "25000.00",
"name": "Voucher Axis Aigo 2GB 24J 30H",
"ep": "660",
"isActive": "Active",
"type": "KUOTA",
"provider": "AXIS DATA"
},
{
"code": "BOLT1",
"price": "31000.00",
"name": "Bolt Kuota 1,5GB 24Jam 30hr",
"ep": "1320",
"isActive": "Active",
"type": "KUOTA",
"provider": "BOLT"
},
{
"code": "BOLT3",
"price": "50000.00",
"name": "Bolt Kuota 3GB 24Jam 30hr",
"ep": "1127",
"isActive": "Active",
"type": "KUOTA",
"provider": "BOLT"
}
],
"respMessage": "PROSES BERHASIL"
}
this is expected new json file
{
"data": [
{
"code": "BXD1",
"price": "15000.00",
"name": "Voucher Axis Aigo 1GB 24J 30H",
"ep": "770",
"isActive": "Active",
"type": "KUOTA",
"provider": "AXIS DATA"
},
{
"code": "BXD2",
"price": "25000.00",
"name": "Voucher Axis Aigo 2GB 24J 30H",
"ep": "660",
"isActive": "Active",
"type": "KUOTA",
"provider": "AXIS DATA"
}
]
}
hasilsearching = hasildata.data[i];should behasilsearching['data'][] = hasildata.data[i];