Dynamic serialisation of data table rows

I often end up serialising data table rows to json and I got tired of writing bespoke serialisers. Here’s my first stab at making a generic serialiser which just works off the table name:


(At some point, I’ll get around to adding the ability to exclude columns in linked tables).


I couldn’t see a way to extract the linked table names and had to resort to passing a dict of those into the function. If anyone can see a way to avoid the need for that dict, I’d love to hear it!

1 Like

Get app_table table object by table ID

bump this one I think…

This is great - and you’re right - it’s a shame you have to define the linked tables dictionary beforehand…

the datatable clearly knows that star_system column belongs to the star_systems table… so why should you have to tell it what it already knows!!!

Screen Shot 2020-02-01 at 10.26.14

I don’t think there would be a nice way to do do this as yet @shaun?

It would be nice if when you do app_tables.planets.list_columns(), instead of:

[{'type': 'string', 'name': 'name'}, 
{'type': 'liveObject', 'name': 'star_system'}]

you got:

[{'type': 'string', 'name': 'name'}, 
{'type': 'liveObject', 'name': 'star_system', 'app_table':'star_systems'}]

or something…


I don’t think there would be a nice way to do do this as yet @shaun?

Correct, you can’t currently get the name of a Data Table (or linked Data Table) programmatically.


I’ve updated the function to handle column exclusion properly.

1 Like

Now refactored, generally tidied up and pretty much about as good as I can get it.


Updated for marshmallow v3.x

Do you have still the example saved somwhere?

That’s now part of anvil extras