One approach is to cast the objects as arrays. I recently had to do this in a project where I retrieved a list of articles and needed to display the featured image. There may be alternate ways to handle this issue, but I’ve found it to be reliable. Here is some relevant code from the project.
<?php
foreach ($articles as $index => $article) {
$article = (array)($article);
$embedded = (array)$article['_embedded'];
$featuredMedia = (array) $embedded['wp:featuredmedia'][0];
$mediaDetails = (array) $featuredMedia['media_details'];
$sizes = (array) $mediaDetails['sizes'];
$mediumLarge = (array) $sizes['medium_large'];
$article_content = "
<div class="col-xs-12 col-md-$count">
<a href="https://wordpress.stackexchange.com/questions/406361/" . $article["link'] . "'>"
.
"<img src="" . $mediumLarge["source_url'] . "'/>".
"<p>" . $article['title']->rendered . "</p>
</a>
</div>
";
echo $article_content;
}