I'm trying to find a record where a column (payload) stores a stringified JSON object. The column type is string (as defined in Prisma schema) — so it's not a JSON or JSONB type.
I want to check if a subset of the JSON content exists in the string, without matching the entire object.
Here's a sample value stored in the payload column:
{
"triggerEvent": "RESERVATION_EXPIRED",
"id": 16,
"eventTypeId": 3,
"userId": 4,
"slotUtcStartDate": "2025-07-25T03:30:00.000Z",
"slotUtcEndDate": "2025-07-25T04:00:00.000Z",
"uid": "014cbb69-fa4b-421b-8c6d-af0ac7f4184e",
"releaseAt": "2025-07-24T20:56:33.000Z",
"isSeat": false
}
I'm only interested in this part of the object:
"eventTypeId": 3,
"userId": 4,
"slotUtcStartDate": "2025-07-25T03:30:00.000Z",
"slotUtcEndDate": "2025-07-25T04:00:00.000Z",
"uid": "014cbb69-fa4b-421b-8c6d-af0ac7f4184e"
Here’s my current Prisma-based query:
const { id, releaseAt, isSeat, ...rest } = slot;
const restString = JSON.stringify(rest);
const searchString = restString.slice(1, -1); // remove outer {}
const isWebhookScheduledTriggerExists = await prisma.webhookScheduledTriggers.findFirst({
where: {
payload: {
contains: searchString,
},
},
});
The Problem:
I was told this approach is inefficient and not production-safe.
Constraint:
I cannot convert the column to JSON/JSONB or change its type — it must remain a string.
My Question:
Is there a more efficient or reliable way to match a partial stringified JSON object in a string column using Prisma or raw SQL?
I was told this approach is inefficient and not production-safe...was a specific reason given for this? If someone is going to give you this kind of feedback they need to provide an explanation, so that you have some idea of what kind of things you might need to change. Get some proper feedback so you've got a clear starting point.I cannot convert the column to JSON/JSONB or change its type — it must remain a stringthis requirement means there's not much else you can do.