My table:
ID | something1 | something2 | ...
1 | meow | 5 |
2 | 4 | KITTIES |
Is there any way to select data as JSON in format {"1":{"something1":"meow","something2":5},"2":{...}}
?
My table:
ID | something1 | something2 | ...
1 | meow | 5 |
2 | 4 | KITTIES |
Is there any way to select data as JSON in format {"1":{"something1":"meow","something2":5},"2":{...}}
?
You can use this library to get an API of the database. Then, consume it! This is the fastest and clearest thing I can imagine.
If you don't mind repeating the ID field in the JSON representation of a row, you can do:
This gives you a JSON object containing a sub-object for each row in the table, keyed by the value in the ID field.
SQLFiddle
See this question for more details.