From 07ccb6380250ae627e85ec8711a638cc313c359e Mon Sep 17 00:00:00 2001 From: Matt Weber Date: Wed, 22 May 2013 11:07:20 -0700 Subject: [PATCH] Stringify object within multi-valued fields If an object is found within an array (nested docs), stringify it during flattening. Closes #100 --- common/lib/shared.js | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/common/lib/shared.js b/common/lib/shared.js index 5dbc38dbe00..44acfd8b9b0 100644 --- a/common/lib/shared.js +++ b/common/lib/shared.js @@ -271,7 +271,17 @@ function flatten_json(object,root,array) { var rootname = root.length == 0 ? index : root + '.' + index; if(typeof obj == 'object' ) { if(_.isArray(obj)) { - if(obj.length === 1 && _.isNumber(obj[0])) { + if(obj.length > 0 && typeof obj[0] === 'object') { + var strval = ''; + for (var objidx = 0, objlen = obj.length; objidx < objlen; objidx++) { + if (objidx > 0) { + strval = strval + ', '; + } + + strval = strval + JSON.stringify(obj[objidx]); + } + array[rootname] = strval; + } else if(obj.length === 1 && _.isNumber(obj[0])) { array[rootname] = parseFloat(obj[0]); } else { array[rootname] = typeof obj === 'undefined' ? null : obj.join(',');