0
votes

Input -

[
{
    "SBQQ__Language__c": "th",
    "SBQQ__APIName__c": "Description",
    "SBQQ__Text__c": null,
    "SBQQ__LongTextArea__c": "Packaging prepress - TH"
},
{
    "SBQQ__Language__c": "th",
    "SBQQ__APIName__c": "Name",
    "SBQQ__Text__c": "ArtPro - TH",
    "SBQQ__LongTextArea__c": null
},
{
    "SBQQ__Language__c": "es",
    "SBQQ__APIName__c": "Name",
    "SBQQ__Text__c": "ArtPro - ES",
    "SBQQ__LongTextArea__c": null
},
{
    "SBQQ__Language__c": "es",
    "SBQQ__APIName__c": "Description",
    "SBQQ__Text__c": null,
    "SBQQ__LongTextArea__c": "Packaging prepress - ES"
},
{
    "SBQQ__Language__c": "de",
    "SBQQ__APIName__c": "Name",
    "SBQQ__Text__c": "ArtPro - DE",
    "SBQQ__LongTextArea__c": null
},
{
    "SBQQ__Language__c": "de",
    "SBQQ__APIName__c": "Description",
    "SBQQ__Text__c": null,
    "SBQQ__LongTextArea__c": "Packaging prepress - DE"
}
]

enter image description here

Required Output:

[
{   
    "locale": "th",
    "name": "ArtPro - TH",
    "description": "Packaging prepress - TH"
},
{
    "locale": "es",
    "name": "ArtPro - ES",
    "description": "Packaging prepress - ES"
},
{   
    "locale": "de",
    "name": "ArtPro - DE",
    "description": "Packaging prepress - DE"
}
]

enter image description here

Note: Mapping -

'locale'        : SBQQ__Language__c,
'name'          : SBQQ__Text__c,
'description'   : SBQQ__LongTextArea__c

I tried using groupBy and then tried to merge but got unsuccessful.

1

1 Answers

0
votes

Try this:

%dw 2.0
output application/dw

---
payload groupBy $.SBQQ__Language__c
mapObject (
    (v,k,i) -> {
        (k): {
            locale: k,
            name: (v filter ($.SBQQ__APIName__c == "Name"))[0].SBQQ__Text__c,
            description: (v filter ($.SBQQ__APIName__c == "Description"))[0].SBQQ__LongTextArea__c
        }
    }

)
pluck $

I had to make certain assumptions considering there was not much explanation provided apart from the input and the output, which was great to attempt to deduce what you wanted. If this is not what your were looking for maybe provide more details in your question and I 'll revise on my end.

I hope it helps.

EDIT: I believe this solution will perform better:

%dw 2.0
output application/dw

---
payload groupBy $.SBQQ__Language__c
mapObject (
    (v,k,i) -> {
        (k): v reduce (e, acc={locale: k}) -> acc ++ do {
            var field = lower(e.SBQQ__APIName__c)
            ---
            (field): if (field == "name") e.SBQQ__Text__c else e.SBQQ__LongTextArea__c
        }
    } 

)
pluck $