Last active
December 10, 2015 23:39
-
-
Save dhensby/4511382 to your computer and use it in GitHub Desktop.
Convert SS_Query results to JSON
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
function queryToJSON(SS_Query $qry) { | |
//the keys you want to code into JSON, this is to white list your array | |
$jsonKeys = array( | |
'ID' => 'ID', | |
'Title' => 'Title', | |
'Content' => 'Content' | |
); | |
$dataToEncode = array(); | |
while ($record = $qry->next()) { | |
$dataToEncode[$record['ID']] = array_intersect_key($record,$jsonKeys); | |
} | |
return Convert::array2json($dataToEncode); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment