JSON Output Formatting?

You access objects by key and arrays by index. Hence order of keys in object is not necessary (and not guaranteed in javascript). Said another way, the value of “oProblem.id” is always returned no matter the order “id” shows up as. Conversely, “oProblem[0]” is never used to get the value of the first key in an object.

Example of iterating objects in Servoy:

/**
 * @properties={typeid:35,uuid:"BD1E4BB4-F1B1-48C5-81BB-1571CD142A5B",variableType:-4}
 */
var myObjectSimple = function() {
	return {
		a: 1,
		b: 2,
		c: "3"
	}
}

/**
 * @properties={typeid:35,uuid:"F1E8AC6B-6884-44C3-9C58-6A4B1ED7CB54",variableType:-4}
 */
var myObjectClosure = function () {
	// total up all numbers with startValue
	var aggregate = function (inputArray, startValue) {
		
		// inputArray is Array?
		if (Array.isArray(inputArray)) {
			inputArray.filter(function(item) {
				return typeof item === "number"
			})
			.map(function (item) {
				startValue += item
			})
		}
		return startValue
	}
	return {
		a: 1,
		b: 2,
		c: "3",
		calc: aggregate
	}
}

/**
 * USAGE: 	#1 processObject(myObjectSimple)  // output order not guaranteed
 * 				-> a: 1.0
 * 				-> b: 2.0
 * 				-> c: 3  
 * 			#2 processObject(myObjectClosure) // w/method on the object
 * 				-> a: 1.0
 * 				-> b: 2.0
 * 				-> c: 3
 * 				-> calc: 3.0 // result of object "api" method
 * 
 * @properties={typeid:35,uuid:"C142B794-16A4-4D8E-9DC5-A64F6C690B3A",variableType:-4}
 */
var processObject = function (factoryFN) {
	var newObject = factoryFN()
	
	// Iterate object version #1
//	if (typeof newObject[prop] === "function") {
//		var sum = newObject[prop]([newObject.a, newObject.b, newObject.c], 0) // example of calling newObject.calc(...) at the destination
//		application.output(prop + ": " + sum)
//	}
//	else {
//		application.output(prop + ": " + newObject[prop])
//	}

	// Iterate object version #2 (preferred)
	Object.keys(newObject).forEach(function (prop) {
	if (typeof newObject[prop] === "function") {
		var sum = newObject[prop]([newObject.a, newObject.b, newObject.c], 0) // example of calling newObject.calc(...) at the destination
		application.output(prop + ": " + sum)
	}
	else {
		application.output(prop + ": " + newObject[prop])
	}
})

Iterating objects in the browser (after calling your REST api endpoint for example) is similar (replace “application.output(…)” with “console.log(…)”)