Repository: sequelize/sequelize
File: packages/core/src/dialects/abstract/data-types.ts (TypeScript)

Code before:
  /** @hidden */
  static readonly [kDataTypeIdentifier]: string = 'JSON';

  protected _checkOptionSupport(dialect: AbstractDialect) {
    super._checkOptionSupport(dialect);
    if (!dialect.supports.dataTypes.JSON) {
      throwUnsupportedDataType(dialect, 'JSON');
    }
  }

  /**
   * We stringify null too.
   */
  acceptsNull(): boolean {
    const sequelize = this._getDialect().sequelize;

    return sequelize.options.nullJsonStringification !== 'sql';
  }

  toBindableValue(value: any): string {
    if (value === null) {
      const sequelize = this._getDialect().sequelize;

      const isExplicit = sequelize.options.nullJsonStringification === 'explicit';
      if (isExplicit) {
        throw new Error('Attempted to insert the JavaScript null into a JSON column, but the "nullJsonStringification" option is set to "explicit", so Sequelize cannot decide whether to use the SQL NULL or the JSON \'null\'. Use the SQL_NULL or JSON_NULL variable instead, or set the option to a different value. See https://sequelize.org/docs/v7/querying/json/ for details.');
      }
    }

    return globalThis.JSON.stringify(value);
  }

  toSql(): string {
    return 'JSON';
  }
}

/**
 * A binary storage JSON column. Only available in Postgres.
 *
 * __Fallback policy:__
 * If the dialect does not support this type natively, an error will be raised.
 *
 * @example
 * ```ts
 * DataTypes.JSONB
 * ```
 *
 * @category DataTypes
 */
export class JSONB extends JSON {

Review comment (suggestion):
```suggestion
        throw new Error(`Attempted to insert the JavaScript null into a JSON column, but the "nullJsonStringification" option is set to "explicit", so Sequelize cannot decide whether to use the SQL NULL or the JSON 'null'. Use the SQL_NULL or JSON_NULL variable instead, or set the option to a different value. See https://sequelize.org/docs/v7/querying/json/ for details.`);
```

Code after:
  /** @hidden */
  static readonly [kDataTypeIdentifier]: string = 'JSON';

  protected _checkOptionSupport(dialect: AbstractDialect) {
    super._checkOptionSupport(dialect);
    if (!dialect.supports.dataTypes.JSON) {
      throwUnsupportedDataType(dialect, 'JSON');
    }
  }

  /**
   * We stringify null too.
   */
  acceptsNull(): boolean {
    const sequelize = this._getDialect().sequelize;

    return sequelize.options.nullJsonStringification !== 'sql';
  }

  toBindableValue(value: any): string {
    if (value === null) {
      const sequelize = this._getDialect().sequelize;

      const isExplicit = sequelize.options.nullJsonStringification === 'explicit';
      if (isExplicit) {
        throw new Error(`Attempted to insert the JavaScript null into a JSON column, but the "nullJsonStringification" option is set to "explicit", so Sequelize cannot decide whether to use the SQL NULL or the JSON 'null'. Use the SQL_NULL or JSON_NULL variable instead, or set the option to a different value. See https://sequelize.org/docs/v7/querying/json/ for details.`);
      }
    }

    return globalThis.JSON.stringify(value);
  }

  toSql(): string {
    return 'JSON';
  }
}

/**
 * A binary storage JSON column. Only available in Postgres.
 *
 * __Fallback policy:__
 * If the dialect does not support this type natively, an error will be raised.
 *
 * @example
 * ```ts
 * DataTypes.JSONB
 * ```
 *
 * @category DataTypes
 */
export class JSONB extends JSON {