zivkovicp

zivkovicp

How to use JSON Schema to create Ecto schema and changesets?

I’m new to Elixir and Phoenix and I’ve been trying to prototype a difficult solution before committing to Phoenix for my new app, but I’m coming up empty handed and need some help!

I need to build dynamic forms using JSON Schema, and I’d prefer to do it in the backend to take advantage of LiveView and server side validation.

My idea was to convert between JSON Schema and Ecto schema/changeset so I could build and validate forms using the server. Every variation of the form has at least 3 unchanging fields and the rest can be saved as JSON in the database. Does this even make sense to do or should I just leverage some front end JS framework that already has support for JSON schema/forms and a rest api?

So far I’ve tried leveraging json_xema, xema, and also failed to build a macro to define a dynamic module with the fields from the JSON Schema (which might be the best solution?)… I’m totally stuck.

In PHP or Python I could probably use a form builder to get this done, but I’m out of my element with Elixir and any sample code, pointers, links to tutorials or docs are appreciated.

Pete

First 5 of 5 Posts Switch mode

marciol

marciol

Are you aware of Schemaless Changesets? It allows the use of schemas from pure data.

dimitarvp

dimitarvp

Yeah, schemaless changesets should serve you fine, you need to write functions to convert the JSON schema to their format but that’s IMO relatively easy.

zivkovicp

zivkovicp OP

Thank you, it seems schemaless changesets just might do the trick. :slight_smile:

egze

egze

Wondering how successful were you at your task? We now need to do the same at work.

Do you have any tips or code examples?

zivkovicp

zivkovicp OP

Hi, sorry for the slow reply but I did not find a solution at the time and ended up using PHP for the project because of familiarity and tooling.

My feeling is that a change of mindset was needed to make it work, and unfortunately I did not have enough time to explore.

— All posts loaded —

Where Next?

Trending in Questions Top

stjefim
Hello! Suppose you are building workflow (order / task / payment) processing system with the following requirements: Each workflow con...
New
jonnycharles
I’m in search of an Elixir library that offers PDF generation capabilities similar to Ruby’s Prawn. While there have been discussions abo...
New
spammy
I’m looking to build a personal workflow to quickly deploy web applications written in elixir/phoenix, for local consumption (ie not on t...
New
silverdr
Using Phoenix.LiveView.TagEngine as an EEx.Engine is deprecated! To compile HEEx, use Phoenix.LiveView.TagEngine.compile/2 instead. Sta...
New
dli
Before I dive in myself, did anyone successfully sprinkle Hologram into their existing LiveView app? Looking for hints regarding: Addi...
New
bottlenecked
Hi all, I wanted to ask how the community is dealing with post-release steps. Today we have Ecto migrations, which make sure that the db...
New
michallepicki
I am using Oban and occasionally, shortly after a deployment, a handful of jobs can fail because of dependency on other parts of the syst...
New

Other Trending Topics Top

JesseHerrick
Hey, I’m Jesse and I’m the main contributor behind Dexter, a full-featured, lightning-fast Elixir LSP optimized for large codebases. It s...
New
jimsynz
Beam Bots (or just BB for short) is a framework for building fault-tolerant robotics applications in Elixir using familiar OTP patterns. ...
New
Damirados
Hello everyone. After busy few months I am happy to announce v0.1.0 of Emerge & Solve. They are GUI (Emerge) and State management (S...
New
ausimian
Emily is an Elixir library that runs Nx computations on Apple’s MLX. Install it as the default Nx backend and Nx, defn, Axon, Nx.Serving,...
New
type1fool
I just stumbled on a newly redesigned elixir-lang.org. :tada: It looks like @Software_Mansion did the work, and I think it is generally a...
New
akoutmos
@hugobarauna and I (Alex Koutmos) have been hard at work on writing a book on Nerves that takes you from simply blinking LEDs to building...
New

We're in Beta

About us Mission Statement