I am currently developing an API that returns JSON structures. One of the domain objects returned is a time series, which is a potentially large list (many thousands of elements) of complex objects.
Say a time series element consists of value
and status
, there are two ways to represent this in JSON. Either as a list of complex objects representing one element each:
{
"timeseries": [
{"value": 1, "status": "OK"},
{"value": 2, "status": "OK"},
{"value": 3, "status": "INVALID"},
// ...
]
}
Or as multiple parallel lists:
{
"timeseries": {
"values": [1, 2, 3, ...],
"status": ["OK", "OK", "INVALID", ...]
}
}
I am wondering if there are any significant advantages of one of those two representations. Right now these seem to be the main differences:
- The list of complex objects seems to be a more natural representation, but is wasteful in that it has to repeat the object keys (
value
andstatus
) many times, even though they never change. - The parallel lists seem harder to deserialize back into a list of element objects and slightly error-prone to going out of sync, but represents the data with less repitition.
I am currently leaning towards using a list of full objects under the assumption that sane clients will always consume the API with some form of compression enabled, making the repetition not be an issue in practice. Are there more things I should be aware of to decide for one or the other?