Issues with JsonArray

My goal today was to finish most of the models that I have been working on and share this with you. However, it is turning out to be a much more complicated problem than I originally thought. I want the JsonArray object to dynamically create JsonObjects (as necessary) when retrieving elements out of the array. However, the JsonObject declaration requires that you know what Object is being passed, and more importantly, what keys to expect.

For example, here is what I have for JsonArray:

Example 1: JsonArray

 * The JsonArray class manages …
 * @namespace Mint.Model
 * @class JsonArray
 * @dependencies library

Mint.Model.JsonArray = function(data) {

Mint.Model.JsonArray.prototype = {
	update: function(data) {
		var that = [];
		this.get = function(i) {
			if (! that[i]) {
				var o = data[i];

				if (isArray(o)) {
					that[i] = new Mint.Model.JsonArray(o);
				else if (isObject(o)) {
					that[i] = new Mint.Model.JsonObject(o);
				else {
					that[i] = o;

			return that[i];

This will work just fine if all values of the array are non-object. However, if it is an Object (most likely, it is), then the JsonObject method is instantiated. The JKEYS array will be empty, because you haven&rsquot;t defined it yet and will throw errors. This has been a real thorn in my side and I have not found a good solution around the issue, except possibly in xJson.

I was planning on playing with xJson separately, but since xJson defines the keys in the JsonArray definition, you can leverage them during the JsonObject instantiation. Also, this has the added benefit of being server driven, without requiring client-side awareness and could make these model objects a little more tamper resistant. I will look into xJson this week and post about it on Friday.