Jesse C Jesse C - 6 months ago 19
JSON Question

JSON Array formatting for questions

Trying to organise a questions based game layout using JSON. Is it better to add an ID identifier into each question or can I use an inbuilt id identifier through each question? The functionality is when a user first clicks on the first question it loads the subQuestion into the next slide.
Thanks

The two ways I think it can be done.

Version 1:

"question": {
"id": "0",
"name": "Incentive Trip",
"subQuestion": {
"name": "Bond Up With Clients",
"subsubQuestion": {
"1,421": "Experiencing Adventures",
"2,284": "Immersing Into Culture",
"3,394": "Overcoming Challenges"
},
"name": "Increase Loyalty",
"subsubQuestion": {
"1,212": "Adding Value",
"2,930": "Making Difference",
"3,489": "Starting VIP club"
},
"name": "Reward Team",
"subsubQuestion ": {
"1,329": "Being A Tourist",
"2,586": "Enjoying Sunshine",
"3,498": "Surprising Colleagues"
}
},
},


Version 2 - No identifier, just nested:

"Marketing Event" : {
"Encourage Relationship": {
"1,398": "Knitting Web",
"2,59": "Rewarding Favourites",
"3,378": "Top Hatting"
},
"Increase Awareness": {
"1,102": "Enjoying The Vibe",
"2,495": "Interacting Through Brand",
"3,697": "Standing Out"
},
"Launch Product": {
"1,287": "Educating Masters",
"2,495": "Shocking Audience",
"3,394": "Steering Wheel"
}
},

Answer

solution 1

Check this answer. Object properties are not in a guaranteed order. So you should definitely add an id if you want to make sure that your users really get the next question.

solution 2

What about mixing mixing up Arrays and objects? Your ids are then the array indexes and the order is guaranteed, as mentioned here.

[
    "Marketing Event" : {
        "Encourage Relationship": {
            "1,398": "Knitting Web",
            "2,59": "Rewarding Favourites",
            "3,378": "Top Hatting"
        },
        "Increase Awareness": {
            "1,102": "Enjoying The Vibe",
            "2,495": "Interacting Through Brand",
            "3,697": "Standing Out"
        },
        "Launch Product": {
            "1,287": "Educating Masters",
            "2,495": "Shocking Audience",
            "3,394": "Steering Wheel"
        }
    },
    "Another Event" : {
        "Another Relationship": {
            "1,398": "Knitting Web",
            "2,59": "Rewarding Favourites",
            "3,378": "Top Hatting"
        },
        "Another Awareness": {
            "1,102": "Enjoying The Vibe",
            "2,495": "Interacting Through Brand",
            "3,697": "Standing Out"
        },
        "Another Product": {
            "1,287": "Educating Masters",
            "2,495": "Shocking Audience",
            "3,394": "Steering Wheel"
        }
    }
]
Comments