I can't find many tips for how to design complex json structures beyond the obvious tips of not trying to nest too deeply, using defined data types, etc.
For example, if I have a location that needs to have security scanning done on all of its segments and devices within the segments, there are many options of how I could do this.
{
"site": "Site 1",
"segments": [
{
"name": "Segment 1",
"devices": [
{
"name": "Device 1",
"scans": [
{
"type": "discovery",
"date": "2016-01-12",
"phase": "10",
"remediate": "0"
},
{} ...
]
},
{} ...
]
},
{} ...
]
}
For this example, a few questions come to mind:
Is it okay to use the property
"name"
twice, since they are on different levels? I've read that it's better to keep the property names short for parsers. Therefore, should you use it twice? Or change them to"seg_name"
and"dev_name"
, for example?You can see a clear pattern for
"segments"
,"devices"
, and"scans"
where they are each an array of objects.
I could change it to something like this:
{
"site": "Site 1",
"segments": {
"Segment 1": {
"Device 1": {
"discovery": {
"date": "2016-01-12",
"phase": "10",
"remediate": "0"
},
"exploit": {} ...
},
"Device 2": {} ...
},
"Segment 2": {} ...
}
}
The issue I can see popping up with this format is that if you wanted to have a property for all of the segments, you would have to put it at the root level, instead of inside the "segments"
property, since the property name could possibly conflict with a segment name. However, it is less nested, which is a plus.
I'm wondering if there are some guidelines of which situations are best suited for a certain format?
If it's really dependent on what language you are using it for, I would be sending the data between JavaScript and PHP.