I’ve downloaded 100 or so questions and stored them as an array in a JSON array like so:
I wrote the following command to try and extract the answer meta data and the corresponding question_id:
Unfortunately this results in an error since some questions haven’t been answered yet and therefore don’t have the ‘answers’ property.
While reading the docs I came across the alternative operation ‘//’ which can be used to provide defaults – in this case I thought I could plugin an empty array of answers if a question hadn’t been answered yet:
Still the same error! Reading down the page I noticed the ? operator which provides syntactic sugar for handling/catching errors. I gave it a try:
As far as I can tell we are just skipping any records that don’t contain ‘answers’ which is exactly the behaviour I’m after so that’s great – just what we need!