Added toJSON method.