I am looking to design a user-friendly form that presents questions for users to navigate, revealing different answers/questions based on their responses. For example:
var json =
{
"Did you restart the computer?": [
{
"Yes": [
{
"Is the software running?": [
{
"Yes": "Cannot help",
"No": "Open it"
}
]
}
],
"No": "Please restart it"
}
]
}
Is there a more efficient data structure than accessing options by keys like json["Did you restart the computer?"][0]["Yes"] and json["Did you restart the computer?"][0]["No"]?
If a user selects "Yes" for the first question, I know I can access keys like this:
Object.keys(json["Did you restart the computer?"][0]["Yes"][0])
>> ['Is the software running?']
And if they select "Yes" again:
Object.keys(json["Did you restart the computer?"][0]["Yes"][0]["Is the software connected to the server?"][0])
>> (2) ['Yes', 'No']
However, this method seems complex. Is there a simpler way to access keys/values using indexes (e.g., json[0][0][1])?