JSON with PostgreSQL not serializing correctly

I have define my field like this:
  hostnames: jsonb("hostnames").$type<string[]>().default([]),


Which looks fine when I look at the table structure.

Now I have the following object I'm creating/updating, which has a string[] as hostnames:
const obj = {
  name: 'foo',
  hostnames: [ 'foo.bar.com' ],
}


After this is added, the value in the database is escaped like this:
"[\"foo.bar.com\"]"

This does not look correct, it looks like wrongly serialized. Or what am I doing wrong here?

The following SQL should extract the first value, however because it's wrongly serialized, it gives me the JSON serialization as the first value:
# select hostnames->>0 from assets limit 5;
              ?column?
════════════════════════════════════
 ["foo.bar.com"]
Was this page helpful?