The output for the JSON data structure with 100 objects should look like this:
[{
"Value": "Sens1_001",
"Parent": Null,
"Child": {
"Value": "Sens2_068",
"Parent":"Sens1_001",
"Child" : {
"Value": "Sens3_034",
"Parent": "Sen2_068",
"Child": null,
"z_cordinate": 5
},
"z_cordinate": 0
},
"z_cordonate": -5
},
{
"Value": "Sens1_002",
"Parent": Null,
"Child": {
"Value": "Sens2_037",
"Parent":"Sens1_002",
"Child" : {
"Value": "Sens3_099",
"Parent": "Sen2_037",
"Child": null,
"z_cordinate": 5
},
"z_cordinate": 0
},
"z_cordonate": -5
},
{
"Value": "Sens1_003",
"Parent": Null,
"Child": {
"Value": "Sens2_012",
"Parent":"Sens1_003",
"Child" : {
"Value": "Sens3_054",
"Parent": "Sen2_012",
"Child": null,
"z_cordinate": 5
},
"z_cordinate": 0
},
"z_cordonate": -5
},
.
.
. // till 100th object
{
"Value": "Sens1_100",
"Parent": Null,
"Child": {
"Value": "Sens2_001",
"Parent":"Sens1_100",
"Child" : {
"Value": "Sens3_021",
"Parent": "Sen2_001",
"Child": null,
"z_cordinate": 5
},
"z_cordinate": 0
},
"z_cordonate": -5
}]
NOTE: I Edited the sample looking object, please review one more time, I changed end braces to look like more an array rather normal object. JSON is secondary, my array should serve my purpose.
Purpose:
How Could I access the objects X.parent.child fashion. I’ve some knowledge but not enough to structure this object. I’m also planning to access the objects either ways, Grapndparent – Parent – Child and Me – Parent – Grandparent. How could I do that? The objects parent – child relationship should be meaningful rather random and moreover a parent can have more than one child.
Since all the ‘value’ key are unique, you can have it as the dictionary key.
So design it like:
Once this dictionary ‘dict’ is ready, if you know the value of the grandparent, then:
Similarly if you know the child’s value,
Tell me if you dont get it still.