I have a question about using a MySQL Query to convert my data into a JSON Object. The Query I have is converting to a JSON Object,
I have learned using array() and trying to create a json which I can use in any mobile application.
mysql data is -
state_name city_name varient_name price
Uttar Pradesh Lucknow varient1 1202
Uttar Pradesh Lucknow varient2 1203
Uttar Pradesh Lucknow varient3 1204
Delhi Faridabad varient1 1206
Delhi Faridabad varient2 1207
Delhi Faridabad varient3 1208
Delhi Saket varient1 1207
Delhi Saket varient2 1208
Delhi Saket varient3 1209
and the response needed in the format -
{
"states": [
{
"state_name": "Uttar Pradesh",
"cities": [
{
"city_name": "Lucknow",
"pricedata": [
{
"varient_name": "varient1",
"varient_price": "1201"
},
{
"varient_name": "varient2",
"varient_price": "1201"
},
{
"varient_name": "varient3",
"varient_price": "1203"
}
]
}
]
},
{
"state_name": "Delhi",
"cities": [
{
"city_name": "Faridabad",
"pricedata": [
{
"varient_name": "varient1",
"varient_price": "1204"
},
{
"varient_name": "varient2",
"varient_price": "1205"
},
{
"varient_name": "varient3",
"varient_price": "1206"
}
]
},
{
"city_name": "Saket",
"pricedata": [
{
"varient_name": "varient1",
"varient_price": "1207"
},
{
"varient_name": "varient2",
"varient_price": "1208"
},
{
"varient_name": "varient3",
"varient_price": "1209"
}
]
}
]
}
]
}