JSON API - integration with Ecto

I’m trying to implement an admin interface for phoenix (like ExAdmin) based on having VueJS forms on the frontend which communicate with the backend using JSON. It would be an npm package with primitive VueJS components + some mix generators to generate forms made out of those components (and possibly controllers to receive the JSON, if it can’t be handled by a generic function). VueJS might seem a little overkill, but I have my reasons.

It’s supposed to be simple CRUD, but it’ll have forms with nested insets. This will require processing nested JSON maps on the backend. Ultimately, those maps will be converted into an Ecto Schema to be sent to the database.

My question is: what would be the simplest way of handling this on the server? Is there any ready-to-use library to convert the (nested) JSON into structures I can insert into the Repo (without DDOSing the BEAM with new atoms)?

I can implement it myself, of course, by introspecting the Ecto schemas and by using something like string_to_existing_atom recursively on the map keys, but if there is a library for already, I could focus on working on the client and generators.

PS: Some justification for the weird design decisions:

  1. I want the forms to reflect changes elsewhere in real time using Phoenix Channels
  2. I want ot make it very easy to edit assocs using insets, select widgets, radio buttons and checkboxes.
  3. I’m using VueJS because it makes the above points very easy, not because I’m a masochist who likes to write JS. Other solutions I’ve seen that use “less JS” end up using JQuery hacks soread around the forms, something I don’t particularly enjoy. Also, well designed VueJS components encapsulate the necessary JS and feel like writinh native HTML widgets.
  4. I want to use generators because I want VueJS components I can edit and customize (change styles, add client side validation, add text in the middle of the form, etc)
  5. Using VueJS single-file components requires Webpack. I don’t really like webpck, but I don’t like Brunch either, so it’s not a great loss…

Sounds like a job for embedded schemas.

Declare an embedded schema to represent the API request as a whole, and additional embedded schemas for each of the nested JSON data.

Then Changeset.cast / Changeset.cast_embed / Changeset.apply_changes will give you nice structs to work with, without any string_to_atom shenanigans.

Probably ExConstructor or Maptu or so?