piccolo-orm/piccolo

Tweak how `ModelBuilder` creates JSON values

dantownsend opened this issue · 0 comments

Currently if you have a table like this:

class RecordingStudio(Table):
    facilities = JSON()

And we use ModelBuilder:

instance = await ModelBuilder.build(RecordingStudio)

The generated JSON value looks something like this (i.e. random string):

>>> instance.facilities
'"absdbsebbsbxn"'

While this is still valid JSON in most cases, some JSON parsers are stricter, and require JSON strings to contain curly brackets.

We should change it slightly, so instead the generated JSON value is something like this:

>>> instance.facilities
'{"value": "absdbsebbsbxn"}'

Which is valid JSON in 100% of cases, and more useful for testing purposes.