Search code examples
javascriptarraysjsonsparse-array

JSON implementations that handle sparse arrays


I need to know if any JSON implementations can handle sparse arrays to my satisfaction. I've seen the question: How to represent a sparse array in JSON? but using an object rather than an array is not an option for me; I need an array.

My minimum requirement would be that the implementation fill in any gaps with "undefined". Otherwise I am writing defensive code that fills in the gaps myself, before JSON encoding.


Solution

  • Not possible. Forget implementations, it's just plain not allowed in the spec.

    http://json.org/

    Arrays are defined by value only. Objects are for when the index/key has meaning.