Convert json to embedded_schema using :source options

Hi, i have an ecto embedded_schema working on a text column that uses :source to read the data as camelCase but have the struct use snake case. I’d like to either parse raw json into that schema or insert it directly into the database.

I can’t change the shape of the data in the database, it’s already in use by a decade old PHP program that i do not want to touch with a 10 foot pole.

Obviously i could go through manually with Macro.underscore but there are a lot of fields and some of them are not camelcased (it’s a legacy codebase) and i’d rather that was handled with ecto

Solved it!

For anyone who finds this thread, the answer was Ecto.embedded_load/3

1 Like