Update page with JSON

I’m trying to update a page by using a route.
What I’m sending:

[{
  'targetId': 'roof',
  'color': 'red'
},
{
  'targetId': 'window',
  'color': 'green'
}]

what I’m trying to achieve:

$page->update([
  'roof' => 'red',
  'window' => 'green'
])

I’m having trouble formatting the JSON correctly…
What I’m doing right now works, but I want to call $page->update() only once and pass all values in an array.

Kirby::plugin('bruno/haus', [
    'routes' => [
        [
            'pattern' => '/setcolor',
            'method' => 'POST',
            'action' => function() {
                $body = file_get_contents('php://input');
                $obj = json_decode($body);
                kirby()->impersonate('kirby');
                foreach($obj as $o) {
                    $page->update([
                       $o->targetId => $o->color
                    ]);
                }
                $res = 'test';
                return Response::json([$res]);
            }
        ]
    ]
]);

Grateful for any help!