I am asking a single.html page to index a JSON data file, and grab values from it.
The catch is, I can’t (ultimately) know the structure of the JSON so the templating needs to be flexible.
I want to say, get the value for the key “head”, but if it’s not there, don’t worry about it, keep going.
Hi, thank you so much for your reply. That’s a good way to access the value.
In this situation though, there are many JSON files, all with different structures, and I can’t know the structure ahead of time. So this example is supposed to be broken. Sorry, it wasn’t the best illustration.
I want to figure out how NOT to get a value if it’s not there, without failing the build.
The only thing I’ve figured out is to explicitly check if it’s an array, using
reflect.IsSlice
But ideally one wouldn’t have to predict the point of failure each time, just be returned nothing.