Using prop=sections returns the "legacy" sections array. But this has some historical artifacts (T319141) and doesn't include top-level extension data for the TOC.
We should add a new prop=tocdata which returns the JSON-serialized form of the TOCData, with the modernized property names and extension data, etc, so we can eventually deprecate the sections property (and uses of SectionMetadata::toLegacyArray()).
$result_array['tocdata'] = JsonCodec::serializeOne( $p_result->getTOCData() )
would be the logical way to write this, but serializeOne is currently private in JsonCodec. But we want a way to get the "array form" of a serializable object, recursively expanding its values as needed, so that we can then give it to the Api framework to encode as JSON or XML or whatever.