Added a toJson() method.