
This question has been answered by upiorz. See the first response.
// getMany returns an array
$children = $modx->resource->getMany('Children');
// now loop through it
foreach ($children as $child) {
// make an array out of each child
$new_item = array(
'name' => $child->get('pagetitle'), // use (-->get) for page properties
'alias' => $child->get('alias'),
'latlng' => $child->getTVValue('map_lat_lng') // use (-->getTVValue) for TVs
);
// finally push all arrays into a single array
array_push($main_array, $new_item);
}
// now you can encode to json
$encoded = json_encode($main_array);
file_put_contents('path/to/your/file.json', $encoded);pay attention that if they are many it is better to use iterator.
https://docs.modx.com/xpdo/2.x/class-reference/xpdo/xpdo.getiterator