Many to many relationships in JSON
As JSON does not have a concept of references, you should not need to worry about them. That which defines what counts as a relation between teachers and students lies outside of the data, i.e. is simply a matter of your interpretation during runtime, through the entities' identifiers.
var faculty = {
"teachers": {
"t1": ["s1","s2","s5"],
"t2": ["s2","s7","s9"]
},
"students": {
"s1": ["t1","t2"],
"s2": ["t2","t7"]
}
}
For example:
alert("Teacher t1's students are: " + faculty.teachers.t1.toString() );
alert("Student s2's teachers are: " + faculty.students.s2.toString() );
alert("Student s2's first teacher's students are: " + faculty.teachers[faculty.students.s2[0]].toString() );
You could make an array of pairs describing the relations as a directed graph?
[// from , to
["s1", "t1"],
["s1", "t2"],
["s2", "t2"],
["s2", "t4"],
["t1", "s1"],
["t1", "s2"],
["t1", "s3"],
["t1", "s4"]
]
It wouldn't be concise. But it would describe your dataset.