Skip to content

SyntaxError: Bad control character in string literal in JSON #2049

@miles-kt-inkeep

Description

@miles-kt-inkeep

When updating a jsonb column to include a string with newlines I get the error: SyntaxError: Bad control character in string literal in JSON

Env

  "dependencies": {
    "drizzle-kit": "^0.31.7",
    "drizzle-orm": "^0.44.7",
    "pg": "^8.16.3",
    "tsx": "^4.20.6"
  },
  "devDependencies": {
    "@types/pg": "^8.15.6"
  }

Drizzle Schema

import { drizzle } from 'drizzle-orm/node-postgres';
import { Pool } from 'pg';
import { jsonb, pgTable, varchar } from 'drizzle-orm/pg-core';
import { eq, sql } from 'drizzle-orm';


  const testTable = pgTable('jsonb_test', {
    id: varchar('id', { length: 256 }).notNull().primaryKey(),
    jsonbColumn: jsonb('jsonb_column').$type<{ test: string }>(),
  });

Example

   // succeeds
    await db.insert(testTable).values({
        id: 'test',
        jsonbColumn: { test: 'value\n' },
    });

    // fails
    await db.update(testTable).set({
        jsonbColumn: { test: 'value\n' },
    }).where(eq(testTable.id, 'test')).returning();

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions