Skip to content

Cannot serialize boolean values for JSON/JSONB columns Β #1003

@darkgnotic

Description

@darkgnotic

Most primitives are successfully serializable into JSON columns, but boolean appears to be the exception.

await db`CREATE TABLE foo(value JSON)`;

for (const value of ['string-value', 123, true]) {
  await db`INSERT INTO foo (value) VALUES (${value})`;
}

// Result: PostgresError: column "value" is of type json but expression is of type boolean

The string and number values are successfully serialized with the JSON type converter, but the boolean is not.

Is it possible that the inferType method is preventing the boolean value from being treated as a JSON value?

Unfortunately I don't understand the type handling code well enough to offer a solution.

Any help is much appreciated! πŸ™

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions