Open
Description
Hi, I was looking for a node.js data transform module, and json2json is great!
I am having a little trouble getting the output data in the exact format that I need.
I am using aggregate to take an array and concatenate with a delimeter. Currently I am only able to get it to work if I nest the aggregate 'key' inside another JSON object.
The desired output is for the aggregate 'key' to be on the root JSON object that is returned.
I think I just have a syntax issue, but after re-arranging many different times, I have not been able to figure it out.
Any help you can offer would be much appreciated.
Here is my template:
path : 'results',
as : {
"Action" : function() { return "Add"; },
"Category" : function() { return ""; },
"Title" : 'title',
"Description" : 'description',
"ConditionID" : 3000,
'' : { // Want to remove this empty 'key' and have 'PicURL' be the only 'key' that holds the aggregated value
path : 'Images',
key: function() { return "PicURL"; },
value : 'url_fullxfull',
aggregate : function(key, value, existing) {
if (existing) {
return existing + "|" + value;
} else {
return value;
}
}
}
Here is the source JSON:
[
{
"count": 602,
"results": [
{
"title": "Works!",
"description": "Works!",
"Images": [
{
"url_fullxfull": "img1"
},
{
"url_fullxfull": "img2"
},
{
"url_fullxfull": "img3"
},
{
"url_fullxfull": "img4"
}
],
}
]
}
]
Here is the output:
[
{
"Action": "Add",
"Category": "",
"Title": "Works!",
"Description": "Works!",
"ConditionID": 3000,
"": { // Want to remove this empty 'key' and have 'PicURL' be the only 'key' that holds the aggregated value
"PicURL": "img1|img2|img3|img4|img5"
},
"Quantity": 1,
"Format": "FixedPrice",
"Duration": "GTC"
}
]
The desired output is:
[
{
"Action": "Add",
"Category": "",
"Title": "Works!",
"Description": "Works!",
"ConditionID": 3000,
"PicURL": "img1|img2|img3|img4|img5",
"Quantity": 1,
"Format": "FixedPrice",
"Duration": "GTC"
}
]