I’ve read through both the RFC and JSON.org and couldn’t see a reference to whether array indexes were 0-based or 1-based. Being originally ‘discovered’ in JS, does everyone just assume it is 0-based?
For example:
{
"selectedItem": 1,
"Items": ["boots", "gloves", "hat"]
}
Is the selected item "boots" or "gloves"?
If this is the case (assumed 0-based), isn’t this assumption potentially troublesome, particular if JSON support is implemented in languages that by default use 1-based indexes?
I don’t think array index is a concept covered by JSON at all. A JSON array is just an ordered set written in a particular fashion:
And that’s all there is to it. Indexing questions are left to the end-points, the first element could be index 0, 1, -10, or
"pancakes"and it wouldn’t make any difference at all to JSON as long as the indexes matched the order of the elements in the array.Back to specifics. Whether
"selectedItem": 1refers to"boots"or"gloves"is up to the JSON producer.