JSON Output Formatting?

bcusick:
Thanks guys! I know that the order doesn’t matter - I was just wondering if there was a way to “prettify” the output. I know that there is no guaranteed “order” when working with object properties… but I just wanted to make sure I wasn’t missing something really obvious. :D

Yea, nothing at the end of that hole. But on a closely related note, changing up your object structure slightly to include an array of keys is a useful pattern. You can still directly access a specific object value by key (one step further removed, ie myObj.items.key instead of myObj.key) and you iterate the additional array of keys to process the keys in order:

/**
 * @properties={typeid:35,uuid:"33E547AA-6395-4EF9-8562-F1A6E6BB5301",variableType:-4}
 */
var myObjectOrdered = function() {
	return {items: {
				a: 1,
				b: 2,
				c: "3" },
			itemsOrder: ['a', 'b', 'c']
	}
}

/**
 * 
 * USAGE: 	processObjectOrdered(myObjectOrdered)  // output order guaranteed
 * 				-> [ 1.0, 2.0, 3 ]
 * 
 * @properties={typeid:35,uuid:"9C49ECBB-A2AA-461A-AB39-33FD0530DBE5",variableType:-4}
 */
var processObjectOrdered = function(factoryFN) {
	var newObject = factoryFN()
	var sampleOutput = []
	
	// Iterate array and use to access object keys
	if ( newObject.hasOwnProperty('itemsOrder') && Array.isArray(newObject['itemsOrder']) ) {
		newObject['itemsOrder'].forEach(function(value) {
			sampleOutput.push(newObject['items'][value])
		})
	}
	
	application.output(sampleOutput)
}

For example if you’re passing back functions instead of scalar values you could execute those functions in order and just choose a specific function to execute.