I need to generate a JSON file for a dataTables section on my web site. The format of the JSON should look like this:
{
"data": [
[
"Tiger Nixon",
"System Architect",
"Edinburgh",
"5421",
"2011/04/25",
"$320,800",
],
[
"Garrett Winters",
"Accountant",
"Tokyo",
"8422",
"2011/07/25",
"$170,750"
],
]
}
This format looks like an array of arrays listed on the JSON Creation Functions (Table 9-42.) -- array_to_json.
However, my data is not stored as arrays in my database. It's typical row data.
But when I try to export to JSON using "row_to_json" -- the format is way off from what I need. See this SQLfiddle example.
Basically, I'm trying to figure out the best approach to make the JSON export look more like the format pasted above.
Should I be reformatting my rows into arrays first, and storing them in a new table, so when I use "row_to_json" they come out as arrays? Or is there a better way?