Saving JSON in Postgres table with Fluent

After a lot of searching for an easy way to do this, it appears that the only way to make this work is to: decode the entire JSON into a custom data type (swift model, not Fluent model) that accurately represents the JSON structure and conforms to PostgresJSONBCodable or PostgresJSONCodable depending on how you want to store it.

Once you have that data storage mechanism, you will decode the JSON into that (swift) model and then encode it into a PostgresData(jsonb: <#T##Data#>) and then make your db query to update the db.

This poses a significant challenge to handling dynamic JSON queries where the structure is unknown, but thankfully that is not the case here and I can rigidly define the data structure. This is sort of a common theme across Swift apps due to the nature of Swift and isn't necessarily a detractor if you value stability and speed.

I am using pieces of information found from these sources to make this determination: