Repository navigation
load_json can't deserialise foreign table.
#1381
from piccolo.columns import ForeignKey, JSON
from piccolo.table import Table
class User(Table):
info = JSON()
class Book(Table):
user = ForeignKey(references=User)
info = JSON()when use:
Is this a designed feature? |
Answered by
dantownsend
Apr 27, 2026
Replies: 1 comment 3 replies
|
@diklios5768 Yes, you are right and currently I don't think Piccolo can automatically deserialize JSON values in nested data. I don't know if there is a better way, but you can do it manually for fk fields in # FastAPI example
import json
@app.get("/objects")
async def root_objects() -> JSONResponse:
data = await Book.objects(Book.user).output(load_json=True)
for item in data:
item["user"]["info"] = json.loads(item["user"]["info"])
return JSONResponse({"data": [d.to_dict() for d in data]})or you can use # FastAPI example
@app.get("/select")
async def root_select() -> JSONResponse:
data = await Book.select(
Book.all_columns(), Book.user.info.as_alias("user_info")
).output(load_json=True, nested=True)
return JSONResponse({"data": data})I hope this helps and makes sense. |
3 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
It ended up being a really simple fix - it will be in the next release.