Not-So Structured Data

I have a personal project that I’m working on that accepts structured JSON data POSTed from an html form (Jquery AJAX). Right now, if I want to expand what I’m handing off to the server, I have to not only change the HTML, but the Go struct that the JSON gets decoded into on the backend using “encoding/json.”

As a future goal, I want to be able to drop template files in a directory that is read on startup to produce the forms, but I obviously won’t be able to create new fields for the structs that way. I’m considering doing away with JSON altogether and just using plaintext key/values, but that feels sloppy. Any suggestions?

Can you show some parts of the code?

in general you could add a map to your struct to handle extra parameters and implement UnmarshalJSON()

For instance

type MyData struct {
    ... // your fields

    Extra map[string]any

in the UnmashalJSON() you can add the not known fields in the Extra; then it really depend which kind of processing you should do …

This is what I ended up going with. Thank you!