© 2026 Hedgehog Software, LLC

TwitterGitHubDiscord
More
CommunitiesDocsAboutTermsPrivacy
Search
Star
Setup for Free
Drizzle TeamDT
Drizzle Team•8mo ago•
1 reply
StillLutto

Json as a string

I currently have this schema:
export const decks = mysqlTable("decks", {
    uuid: char("uuid", { length: 36 }).primaryKey(),
    name: varchar("name", { length: 25 }).notNull(),
    cards: json("cards").$type<Card[]>().default([]).notNull(),
    createdAt: timestamp("created_at").defaultNow(),
    updatedAt: timestamp("updated_at").defaultNow(),
});

export const ZodCard = z.object({
    question: z.string("question").max(255).min(6),
    answer: z.string("answer").max(255).min(6),
})
export type Card = z.infer<typeof ZodCard>;
export const decks = mysqlTable("decks", {
    uuid: char("uuid", { length: 36 }).primaryKey(),
    name: varchar("name", { length: 25 }).notNull(),
    cards: json("cards").$type<Card[]>().default([]).notNull(),
    createdAt: timestamp("created_at").defaultNow(),
    updatedAt: timestamp("updated_at").defaultNow(),
});

export const ZodCard = z.object({
    question: z.string("question").max(255).min(6),
    answer: z.string("answer").max(255).min(6),
})
export type Card = z.infer<typeof ZodCard>;


When I get the set of cards from a deck as such:
db.query.decks.findFirst({
  where: ((deck, { eq }) => eq(deck.uuid, input.uuid)),
}).then((deck) => deck?.cards || []))
db.query.decks.findFirst({
  where: ((deck, { eq }) => eq(deck.uuid, input.uuid)),
}).then((deck) => deck?.cards || []))


It returns this string:
"[]"
"[]"
. It's
$type<Card[]>()
$type<Card[]>()
supposed to serialize and deserialize it for me?
Drizzle TeamJoin
The official Discord for all Drizzle related projects, such as Drizzle ORM, Drizzle Kit, Drizzle Studio and more!
11,879Members
Resources

Similar Threads

Was this page helpful?
Recent Announcements

Similar Threads

Mysql JSON_ARRAYAGG as a string instead of a json
Drizzle TeamDTDrizzle Team / help
3y ago
json column returning as string
Drizzle TeamDTDrizzle Team / help
6mo ago
Json column type returning as plain string?
Drizzle TeamDTDrizzle Team / help
16mo ago
Timestamp as string
Drizzle TeamDTDrizzle Team / help
3y ago