In Magento 2, I can get a category tree with the following
$tree = $this->treeFactory->create(); var_dump( $tree->getTree( $tree->getRootNode() )->getData() );
However, the data in the
children_data property will be a PHP array of full PHP category objects
'children_data' => array (size=8) 0 => object(Magento\Catalog\Model\Category\Interceptor) protected '_eventPrefix' => string 'catalog_category' (length=16)
I'd like this data to be serialized is a json friendly way -- i.e., no PHP objects.
Is there an elegant way of doing this? -- I know the native Magento 2 API supports JSON output (using native category objects via service contracts), so somewhere in Magento 2 is code that will do the serialization I'm after. I'm just not familiar enough with Magento 2's architecture to drag this up myself.