Skip to content

How to encode prisma find many result as JSON? #332

Answered by RobertCraigie
felinto-dev asked this question in Q&A
Discussion options

You must be logged in to vote

Prisma queries return pydantic models. If you need to serialise a model to JSON then you simply have to call .json().

Serialising a list of models is more complicated, but this should work for you (I'm on mobile and can't confirm at the moment):

from typing import List
from pydantic import BaseModel
from prisma.models import DownloadRequest

class DownloadRequestList(BaseModel):
    __root__: List[DownloadRequest]

data = DownloadRequestList(__root__=downloads)
return data.json()

Replies: 1 comment 5 replies

Comment options

You must be logged in to vote
5 replies
@felinto-dev
Comment options

@RobertCraigie
Comment options

@RobertCraigie
Comment options

@felinto-dev
Comment options

@RobertCraigie
Comment options

Answer selected by felinto-dev
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants