Elm-Detroit / elm-detroit

4 stars 3 forks source link

Generating Elm JSON Decoders based on JSON Schema #5

Open jpierson opened 6 years ago

jpierson commented 6 years ago

I'm tackling my first pet Elm project in the open and have run into the need to read data provided in JSON format. Lucky for me the specific JSON format has an associated JSON Schema defined so I was hoping to be able to generate the corresponding Elm Decoders based on the JSON Schema but unfortunately I haven't found a specific general purpose tool or Elm package for doing so. If this package is not yet available it may provide for a good project for those complete Elm beginners like myself to both learn about JSON Decoders and perhaps give back to the Elm community by creating an Elm package that could simplify working with JSON data.

I probably won't be able to lead such an endeavor myself just yet as I'm only just learning Elm in my limited spare time but I would be happy to help out and contribute to anybody that would be interested in taking it on. Alternatively if I make progress on this front I would be happy to share in the form of a presentation if there is interest.

Related resources:

jwoudenberg commented 6 years ago

Hey @jpierson, thanks for the issue and sorry for the slow response, I was on a holiday last week.

We have the JsonSchema.Decode, which provides a JSON decoder that can take a JSON schema (which is itself a valid json document) and decode it into the elm-json-schema type this library provides. To do what you would like to do, we'd need the following additions:

PR's to address either or both of these points are very welcome!

jpierson commented 6 years ago

The initial approach that we have started with is to leverage the json-elm-schema project to generate Elm types that are then fed into the json-to-elm tool to generate the corresponding decoders.

To prove this out we attempted to leverage the CLI tool but ran into issues getting the NPM package to install in Windows and then ran into issues on my laptop getting NPM stuff installed through WSL. We would like to test an example schema through the pipeline of these two project to see if we can put some Elm and NPM packages together to leverage these two tools together if possible to achieve the original goal of this project.