Fix error when the toJSON method return a non-object value.