<?php class Foo implements JsonSerializable { private $thing; public function __construct($thing) { $this->thing = $thing; } public function jsonSerialize() { return [ 'thing' => $this->thing, ]; } } $foo = new Foo('Foo Bar'); echo json_encode(['the_foo' => $foo]);
You have javascript disabled. You will not be able to edit any code.