PyDAL issues with json

37 views
Skip to first unread message

Maurice Waka

unread,
Apr 5, 2026, 9:00:48 AMApr 5
to py4web

When I used PostgreSQL (including NeonDB), and inserting into a Field('images', 'json') column, I noted tht it fails even when passing a properly serialized JSON string via json.dumps().

Instead of inserting the correct JSON value (e.g. ["images/pets.jpg"]), pyDAL inserts a corrupted string containing its internal list separator ('||'), resulting in:

SQL
invalid input syntax for type json
DETAIL: Token "|" is invalid.
CONTEXT: JSON data, line 1: |...

what I did

  1. Define table with PostgreSQL:

    Field('images', 'json')
  2. In an @action, do:
    Python
    images_value = json.dumps(["images/test.jpg"])
    db.mytable.insert(..., images=images_value)

Massimo DiPierro

unread,
May 9, 2026, 7:00:08 PMMay 9
to py4web

If a file is JSON you should not store a string in it but a proper object:

images_value = json.dumps(["images/test.jpg"])
db.mytable.insert(..., images=images_value)

If you want to store a string-serialized json than make the field of type "text" not "json".
Reply all
Reply to author
Forward
0 new messages