added toJSON methods on key classes