In ujson I have JSON structures like this:
{ "input": "alfred",
"result": [
{
"name": "Alfred Pulipuli",
"job": "hair dresser",
"location": {
"x": 149.1780959,
"y": -35.24640164
},
"more": {
"member": true,
"certified": "level1"
}
},
{
"name": "Alfred J Carubel",
"job": "bear trimmer",
"more": {
"member": false,
"certified": "level1"
}
}]
}
From these structures I want extract the job descriptions (here [ "hair dresser", "bear trimmer"]), which is easy to do like data("result")....
But what if the input JSON in data does not adhere to this structure?
Well, I can use exception handling:
Try:
data("result")...
match:
case Success(result) => result
case Failure(_) => ujson.Arr()
However I think this is not v ery functional, because I use exception handling. What would be a more functional approach? Defining first a schema? (I don’t care whether the other JSON attributes are correct.)
All pointers are appreciated!