JSON Output in a Specific Format. - Printable Version +- CodeIgniter Forums (https://forum.codeigniter.com) +-- Forum: Using CodeIgniter (https://forum.codeigniter.com/forumdisplay.php?fid=5) +--- Forum: General Help (https://forum.codeigniter.com/forumdisplay.php?fid=24) +--- Thread: JSON Output in a Specific Format. (/showthread.php?tid=67354) |
JSON Output in a Specific Format. - Speed - 02-13-2017 Hi, I'm trying to work out how to output some data in JSON with this specific format: '{"rows": [ {"Firstname": "John", "Lastname": "Smith" }, {"Firstname": "Jane", "Lastname": "Doe" } ] }' As an example, I've gotten close to what I need with something similar to this (except I don't need the index numbers).... PHP Code: $name['firstname'] = 'John'; ....but it's not quite there: '{"1":{"firstname":"John","lastname":"Smith"},"2":{"firstname":"Jane","lastname":"Doe"}}' As you can see I need it to start with {"rows":[ and end with ]}. Any guidance would much appreciated. Thanks, Steve CodeIgniter 3.0.0 RE: JSON Output in a Specific Format. - ciadmin - 02-13-2017 You might try Code: $names[] = $name; RE: JSON Output in a Specific Format. - Speed - 02-13-2017 (02-13-2017, 09:50 PM)ciadmin Wrote: You might try That's perfect. Thank you! All I have to do then is add the extra bits and I get the exact output I need: PHP Code: $this->output Thank you again! Steve |