Add implementation for toJson() and JSON constructor