Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Help understanding Aggregate #10

Open
rosenjason opened this issue Nov 5, 2014 · 5 comments
Open

Help understanding Aggregate #10

rosenjason opened this issue Nov 5, 2014 · 5 comments
Labels

Comments

@rosenjason
Copy link

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"
        }
    ]
@lpww
Copy link

lpww commented Mar 23, 2016

I too would like to see better documentation surrounding the aggregate functionality. It is not clear how it works

@peteashworth
Copy link

ditto

@joelvh
Copy link
Owner

joelvh commented Sep 7, 2016

Hi all, I have not used this library in a long time. You'll have to look at the source code to determine how things work, and whether any updates need to be done. Please add documentation and submit a PR if you dig in. Thanks!

@joelvh
Copy link
Owner

joelvh commented Aug 3, 2017

@lpww @rosenjason @AshworthHub have you guys continued using this library? Could you contribute more information about how aggregate works? Would be greatly appreciated!

@joelvh joelvh added the docs label Aug 3, 2017
@rosenjason
Copy link
Author

rosenjason commented Aug 22, 2017

Hi @joelvh, I don't use this API anymore... once I had trouble figuring out the "aggregate" function, I found another API that did JSON data mappings and forked it: jsont

I found the jsont API cleaner and easier to use. I also added asynchronous event streaming capabilities to improve performance and allow for processing millions of records. Streaming also allows for sending processed records to alternate storage (like a DB, file, call another web endpoint, etc)

I added functionality for partial templates allowing for templates to be embedded and re-used. Like for addresses, line items on an order, shipping options, etc.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

4 participants