lib/json-parser.js
function _flattenSillyArray(parentObj, key, requestContext) {
  //debug('_flattenSillyArray', key, parentObj[key]);

  var subKey = key.replace(/Array$/, '');   // e.g. 'Order' from 'OrderArray'
  var newKey = subKey + 's';                // e.g. 'Orders'

  // `compact` avoids creating an array of `[undefined]`,
  // from input `['']` when xml "array" element was empty.
  parentObj[newKey] = _.compact(parentObj[key][0][subKey]);
  delete parentObj[key];

  // might have already been flattened...
  if (!_.isArray(parentObj[newKey])) parentObj[newKey] = [ parentObj[newKey] ];

  parentObj[newKey] = parentObj[newKey].map(function(subObj) {
    return exports.flatten(subObj, -1, requestContext);
  });

  return newKey;
}
function _flattenSillyArray(parentObj, key, requestContext) {
  //debug('_flattenSillyArray', key, parentObj[key]);

  var subKey = key.replace(/Array$/, '');   // e.g. 'Order' from 'OrderArray'
  var newKey = subKey + 's';                // e.g. 'Orders'

  // `compact` avoids creating an array of `[undefined]`,
  // from input `['']` when xml "array" element was empty.
  parentObj[newKey] = _.compact(parentObj[key][0][subKey]);
  delete parentObj[key];

  // might have already been flattened...
  if (!_.isArray(parentObj[newKey])) parentObj[newKey] = [ parentObj[newKey] ];

  parentObj[newKey] = parentObj[newKey].map(function(subObj) {
    return exports.flatten(subObj, -1, requestContext);
  });

  return newKey;
}
function _flattenSillyArray ( parentObj , key , requestContext ) { //debug('_flattenSillyArray', key, parentObj[key]); var subKey = key . replace ( / Array$ / , '' ) ; // e.g. 'Order' from 'OrderArray' var newKey = subKey + 's' ; // e.g. 'Orders' // `compact` avoids creating an array of `[undefined]`, // from input `['']` when xml "array" element was empty. parentObj [ newKey ] = _ . compact ( parentObj [ key ] [ 0 ] [ subKey ] ) ; delete parentObj [ key ] ; // might have already been flattened... if ( ! _ . isArray ( parentObj [ newKey ] ) ) parentObj [ newKey ] = [ parentObj [ newKey ] ] ; parentObj [ newKey ] = parentObj [ newKey ] . map ( function ( subObj ) { return exports . flatten ( subObj , - 1 , requestContext ) ; } ) ; return newKey ; }
/*
convert `OrderArray: [ Order: [...] ]` structure to `Orders: []`.
@param parentObj: the obj *containing* the key to be restructured.
@param key: the key within the object to fix.
modifies byref.
@return new key.
/ * convert OrderArray : [ Order : [ ... ] ] structure to Orders : [] .