I have an expected JSON payload that is fairly deep in nested arrays/objects. As I am assigning variables based on the assumed structure
{
id: value1,
name: value2,
data: {
status: complete,
date: 2020 - 06 - 20,
notes: {
field1: "user notes",
field2: "more user notes"
}
}
}
In my code I will make a call like this:
var usernote = payload.data.notes.field1 || "No Notes"
But it may occur that the user raised no notes, so the notes object will return as undefined. Is there anyway around this without doing a set of cascading default checks? Some of my calls look like this:
priorityvar = payload.data.form_values["b691"][index]["form_values"]["d54d"]["choice_values"][0]
Any help would be greatly appreciated, I couldnt find a similar answer in my search (but very new to here too). Also I am working in google scripts so I cant use any ES6 stuff.