javascript - JSON object - which structure makes more sense? -


i'm learning json & javascript objects , trying figure out best way structure object particular project.

i think i've mapped out object pretty well, i've thought of 2 different ways of doing , i'm not sure 'better' , implications of doing 1 way rather other.

    {     "session": {         "sessionid": "",         "sessiontitle": "",         "sessiondescription": "",         "clientname": "",         "sessiontopics": [{             "topicnames": [                 "name of first topic",                 "name of second topic",                 "name of third topic",                 "name of fourth topic",                 "name of fifth topic"             ],             "topicchoices": [                 ["a", "c", "a", "b", "e", "a", "d", "e", "c", "b"],                 ["c", "b", "a", "c", "d", "a", "b", "c", "a", "b"],                 ["a", "b", "a", "b", "e", "a", "d", "e", "c", "d"],                 ["a", "c", "a", "b", "e", "a", "d", "e", "c", "b"],                 ["c", "d", "b", "c", "e", "b", "d", "e", "c", "a"]             ],             "topiclmode": [                 7, 9, 6, 9, 5             ]         }],         "imagedescriptions": [             "client's description of image a",             "client's description of image b",             "client's description of image c",             "client's description of image d",             "client's description of image e"         ]     } } 

-- or --

{     "session": {         "sessionid": "",         "sessiontitle": "",         "sessiondescription": "",         "clientname": "",         "sessiontopics": [{             "firsttopic": [{                 "topicname": "name of first topic",                 "topicchoices": [                     "b", "c", "a", "d", "e", "a", "e", "b", "c", "b"                 ],                 "lmoderating" : 7             }]         }, {             "secondtopic": [{                 "topicname": "second topic name",                 "topicchoices": [                     "a", "c", "a", "b", "e", "a", "d", "e", "c", "b"                 ],                 "lmoderating": 9             }]             }, {             "thirdtopic": [{                 "topicname": "third topic name",                 "topicchoices": [                     "a", "c", "a", "b", "e", "a", "d", "e", "c", "b"                 ],                 "lmoderating": 6             }]             }, {             "fourthtopic": [{                 "topicname": "fourth topic name",                 "topicchoices": [                     "a", "c", "a", "b", "e", "a", "d", "e", "c", "b"                 ],                 "lmoderating": 9             }]             }, {             "fifthtopic": [{                 "topicname": "fifth topic name",                 "topicchoices": [                     "a", "c", "a", "b", "e", "a", "d", "e", "c", "b"                 ],                 "lmoderating": 5             }]         }],         "imagedescriptions": [         {             "imagea": "description of image a"         }, {             "imageb": "description of image b"         }, {             "imagec": "description of image c"         }, {             "imaged": "description of image d"         }, {             "imagee": "description of image e"         }         ],     } } 

i don't know whether makes difference better, won't know ahead of time how many "topics" there in each session (i know 4-6 topics).

also possibly relevant -- i'll need able data topic calculations , output, calculations across topics (e.g., comparing 'topicchoices' across 2 topics - 4th choice same in topic 1 in topic 4?).

my gut tells me perhaps makes first approach better (easier work with), i'm not sure.

i'm open suggestions!

thanks scott

i suggest 3rd version, allows better iteration of sessiontopics

var data = {     "session": {         "sessionid": "",         "sessiontitle": "",         "sessiondescription": "",         "clientname": "",         "sessiontopics": [             {                 "topicname": "name of first topic",                 "topicchoices": [                     "b", "c", "a", "d", "e", "a", "e", "b", "c", "b"                 ],                 "lmoderating": 7             }, {                 "topicname": "second topic name",                 "topicchoices": [                     "a", "c", "a", "b", "e", "a", "d", "e", "c", "b"                 ],                 "lmoderating": 9             }         ],         "imagedescriptions": [             {                 "imagea": "description of image a"             }, {                 "imageb": "description of image b"             }, {                 "imagec": "description of image c"             }, {                 "imaged": "description of image d"             }, {                 "imagee": "description of image e"             }         ],     } }; 

Comments

Popular posts from this blog

java - Jasper subreport showing only one entry from the JSON data source when embedded in the Title band -

serialization - Convert Any type in scala to Array[Byte] and back -

SonarQube Plugin for Jenkins does not find SonarQube Scanner executable -