When I first read the JSON format specification, I was under the impression that an object was a collection of key-value pairs (with the value being of any type) and an array was a collection of zero or more elements of the same type.
object (mixed values):
{
"key": "value",
"key2": 2
}
array (single type):
[1, 2, 3]
["one", "two", "three"]
[
{"key": "value"},
{"key2": 2}
]
I encountered some examples that included arrays with elements of mixed types. After testing that this is legitimate in Node.js, I'm left wondering: why have two different collection types that are so similar?
array (mixed types):
[1, "two", {"three": 4}]
The only major difference I can see is that arrays don't require a "key" for every "value". Are there any other significant differences?
EDIT:
Given the duplicate question of the original, and that an array is a dressed up object, I've modified the question slightly. (Apologies to the original answers.)
My best guess is that arrays are extremely common and adding a syntax and predefined class for them is mostly for convenience.
Possible duplicate/reference question: What is the difference between an array and an object?