Help understanding Aggregate
- Dominant language
- CoffeeScript
- Stars
- 191
- Forks
- 36
- PR merge metrics
- No merged PRs in 30d
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"
}
]
```
Contributor guide
No contributing guide indexed for this repository
Research direction
Start with the aggregate configuration shown in the issue and inspect json2json's aggregate handling; no source file or test is named. Reproduce the template with the supplied JSON, and consider the issue done when PicURL is emitted at the root without the empty wrapper key.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- javascript, node.js
- Domain
- tooling
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100