Convert array of json into single json with inner array

Multi tool use
Multi tool use





.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty{ height:90px;width:728px;box-sizing:border-box;
}







0















I'm getting a message from a system in json format and want to perform a transformation in order to get below message



Source message:



    [
{
"OPERATING_COMPANY": "xx",
"STORE_CLOSING_TIME": "2019-01-03T22:00:00",
"BATCH_ID": 1812,
"STORENUMBER": 1197,
"PROCESS_STATUS": "P"
},
{
"OPERATING_COMPANY": "xx",
"STORE_CLOSING_TIME": "2019-01-04T18:00:00",
"BATCH_ID": 1812,
"STORENUMBER": 1197,
"PROCESS_STATUS": "P"
},
{
"OPERATING_COMPANY": "xx",
"STORE_CLOSING_TIME": "2019-01-03T22:00:00",
"BATCH_ID": 1314,
"STORENUMBER": 1198,
"PROCESS_STATUS": "P"
},
{
"OPERATING_COMPANY": "xx",
"STORE_CLOSING_TIME": "2019-01-04T18:00:00",
"BATCH_ID": 1314,
"STORENUMBER": 1198,
"PROCESS_STATUS": "P"
}]


Expected Output



    [
{
"OPERATING_COMPANY": "xx",
"STORE_CLOSING_TIME": ["2019-01-03T22:00:00","2019-01-04T18:00:00"],
"BATCH_ID": 1812,
"STORENUMBER": 1197,
"PROCESS_STATUS": "P"
},
{
"OPERATING_COMPANY": "xx",
"STORE_CLOSING_TIME": ["2019-01-03T22:00:00","2019-01-04T18:00:00"],
"BATCH_ID": 1812,
"STORENUMBER": 1198,
"PROCESS_STATUS": "P"
}]


I'm new to dataweave and tried using map but not able to understand how to achieve result.










share|improve this question























  • Please post what you have tried so we may assist in fixing it.

    – Mark Schultheiss
    Jan 3 at 22:14











  • What version of mule?

    – machaval
    Jan 3 at 22:25


















0















I'm getting a message from a system in json format and want to perform a transformation in order to get below message



Source message:



    [
{
"OPERATING_COMPANY": "xx",
"STORE_CLOSING_TIME": "2019-01-03T22:00:00",
"BATCH_ID": 1812,
"STORENUMBER": 1197,
"PROCESS_STATUS": "P"
},
{
"OPERATING_COMPANY": "xx",
"STORE_CLOSING_TIME": "2019-01-04T18:00:00",
"BATCH_ID": 1812,
"STORENUMBER": 1197,
"PROCESS_STATUS": "P"
},
{
"OPERATING_COMPANY": "xx",
"STORE_CLOSING_TIME": "2019-01-03T22:00:00",
"BATCH_ID": 1314,
"STORENUMBER": 1198,
"PROCESS_STATUS": "P"
},
{
"OPERATING_COMPANY": "xx",
"STORE_CLOSING_TIME": "2019-01-04T18:00:00",
"BATCH_ID": 1314,
"STORENUMBER": 1198,
"PROCESS_STATUS": "P"
}]


Expected Output



    [
{
"OPERATING_COMPANY": "xx",
"STORE_CLOSING_TIME": ["2019-01-03T22:00:00","2019-01-04T18:00:00"],
"BATCH_ID": 1812,
"STORENUMBER": 1197,
"PROCESS_STATUS": "P"
},
{
"OPERATING_COMPANY": "xx",
"STORE_CLOSING_TIME": ["2019-01-03T22:00:00","2019-01-04T18:00:00"],
"BATCH_ID": 1812,
"STORENUMBER": 1198,
"PROCESS_STATUS": "P"
}]


I'm new to dataweave and tried using map but not able to understand how to achieve result.










share|improve this question























  • Please post what you have tried so we may assist in fixing it.

    – Mark Schultheiss
    Jan 3 at 22:14











  • What version of mule?

    – machaval
    Jan 3 at 22:25














0












0








0








I'm getting a message from a system in json format and want to perform a transformation in order to get below message



Source message:



    [
{
"OPERATING_COMPANY": "xx",
"STORE_CLOSING_TIME": "2019-01-03T22:00:00",
"BATCH_ID": 1812,
"STORENUMBER": 1197,
"PROCESS_STATUS": "P"
},
{
"OPERATING_COMPANY": "xx",
"STORE_CLOSING_TIME": "2019-01-04T18:00:00",
"BATCH_ID": 1812,
"STORENUMBER": 1197,
"PROCESS_STATUS": "P"
},
{
"OPERATING_COMPANY": "xx",
"STORE_CLOSING_TIME": "2019-01-03T22:00:00",
"BATCH_ID": 1314,
"STORENUMBER": 1198,
"PROCESS_STATUS": "P"
},
{
"OPERATING_COMPANY": "xx",
"STORE_CLOSING_TIME": "2019-01-04T18:00:00",
"BATCH_ID": 1314,
"STORENUMBER": 1198,
"PROCESS_STATUS": "P"
}]


Expected Output



    [
{
"OPERATING_COMPANY": "xx",
"STORE_CLOSING_TIME": ["2019-01-03T22:00:00","2019-01-04T18:00:00"],
"BATCH_ID": 1812,
"STORENUMBER": 1197,
"PROCESS_STATUS": "P"
},
{
"OPERATING_COMPANY": "xx",
"STORE_CLOSING_TIME": ["2019-01-03T22:00:00","2019-01-04T18:00:00"],
"BATCH_ID": 1812,
"STORENUMBER": 1198,
"PROCESS_STATUS": "P"
}]


I'm new to dataweave and tried using map but not able to understand how to achieve result.










share|improve this question














I'm getting a message from a system in json format and want to perform a transformation in order to get below message



Source message:



    [
{
"OPERATING_COMPANY": "xx",
"STORE_CLOSING_TIME": "2019-01-03T22:00:00",
"BATCH_ID": 1812,
"STORENUMBER": 1197,
"PROCESS_STATUS": "P"
},
{
"OPERATING_COMPANY": "xx",
"STORE_CLOSING_TIME": "2019-01-04T18:00:00",
"BATCH_ID": 1812,
"STORENUMBER": 1197,
"PROCESS_STATUS": "P"
},
{
"OPERATING_COMPANY": "xx",
"STORE_CLOSING_TIME": "2019-01-03T22:00:00",
"BATCH_ID": 1314,
"STORENUMBER": 1198,
"PROCESS_STATUS": "P"
},
{
"OPERATING_COMPANY": "xx",
"STORE_CLOSING_TIME": "2019-01-04T18:00:00",
"BATCH_ID": 1314,
"STORENUMBER": 1198,
"PROCESS_STATUS": "P"
}]


Expected Output



    [
{
"OPERATING_COMPANY": "xx",
"STORE_CLOSING_TIME": ["2019-01-03T22:00:00","2019-01-04T18:00:00"],
"BATCH_ID": 1812,
"STORENUMBER": 1197,
"PROCESS_STATUS": "P"
},
{
"OPERATING_COMPANY": "xx",
"STORE_CLOSING_TIME": ["2019-01-03T22:00:00","2019-01-04T18:00:00"],
"BATCH_ID": 1812,
"STORENUMBER": 1198,
"PROCESS_STATUS": "P"
}]


I'm new to dataweave and tried using map but not able to understand how to achieve result.







mule dataweave






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Jan 3 at 21:51









Piyush SinghPiyush Singh

326




326













  • Please post what you have tried so we may assist in fixing it.

    – Mark Schultheiss
    Jan 3 at 22:14











  • What version of mule?

    – machaval
    Jan 3 at 22:25



















  • Please post what you have tried so we may assist in fixing it.

    – Mark Schultheiss
    Jan 3 at 22:14











  • What version of mule?

    – machaval
    Jan 3 at 22:25

















Please post what you have tried so we may assist in fixing it.

– Mark Schultheiss
Jan 3 at 22:14





Please post what you have tried so we may assist in fixing it.

– Mark Schultheiss
Jan 3 at 22:14













What version of mule?

– machaval
Jan 3 at 22:25





What version of mule?

– machaval
Jan 3 at 22:25












1 Answer
1






active

oldest

votes


















0














Try the following in dataweave:



%dw 1.0
%output application/json
%var time=(payload map $.STORE_CLOSING_TIME) distinctBy $.STORE_CLOSING_TIME
---
(payload map {

"OPERATING_COMPANY": $.OPERATING_COMPANY,
"STORE_CLOSING_TIME": time,
"BATCH_ID": $.BATCH_ID,
"STORENUMBER": $.STORENUMBER,
"PROCESS_STATUS": $.PROCESS_STATUS
}) distinctBy $.STORENUMBER


output:



[
{
"OPERATING_COMPANY": "xx",
"STORE_CLOSING_TIME": [
"2019-01-03T22:00:00",
"2019-01-04T18:00:00"
],
"BATCH_ID": 1812,
"STORENUMBER": 1197,
"PROCESS_STATUS": "P"
},
{
"OPERATING_COMPANY": "xx",
"STORE_CLOSING_TIME": [
"2019-01-03T22:00:00",
"2019-01-04T18:00:00"
],
"BATCH_ID": 1314,
"STORENUMBER": 1198,
"PROCESS_STATUS": "P"
}
]





share|improve this answer


























  • updated the mapping

    – Anirban Sen Chowdhary
    Jan 3 at 23:14











  • Works just fine...thanks

    – Piyush Singh
    Jan 4 at 8:13












Your Answer






StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");

StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














draft saved

draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f54030303%2fconvert-array-of-json-into-single-json-with-inner-array%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown

























1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes









0














Try the following in dataweave:



%dw 1.0
%output application/json
%var time=(payload map $.STORE_CLOSING_TIME) distinctBy $.STORE_CLOSING_TIME
---
(payload map {

"OPERATING_COMPANY": $.OPERATING_COMPANY,
"STORE_CLOSING_TIME": time,
"BATCH_ID": $.BATCH_ID,
"STORENUMBER": $.STORENUMBER,
"PROCESS_STATUS": $.PROCESS_STATUS
}) distinctBy $.STORENUMBER


output:



[
{
"OPERATING_COMPANY": "xx",
"STORE_CLOSING_TIME": [
"2019-01-03T22:00:00",
"2019-01-04T18:00:00"
],
"BATCH_ID": 1812,
"STORENUMBER": 1197,
"PROCESS_STATUS": "P"
},
{
"OPERATING_COMPANY": "xx",
"STORE_CLOSING_TIME": [
"2019-01-03T22:00:00",
"2019-01-04T18:00:00"
],
"BATCH_ID": 1314,
"STORENUMBER": 1198,
"PROCESS_STATUS": "P"
}
]





share|improve this answer


























  • updated the mapping

    – Anirban Sen Chowdhary
    Jan 3 at 23:14











  • Works just fine...thanks

    – Piyush Singh
    Jan 4 at 8:13
















0














Try the following in dataweave:



%dw 1.0
%output application/json
%var time=(payload map $.STORE_CLOSING_TIME) distinctBy $.STORE_CLOSING_TIME
---
(payload map {

"OPERATING_COMPANY": $.OPERATING_COMPANY,
"STORE_CLOSING_TIME": time,
"BATCH_ID": $.BATCH_ID,
"STORENUMBER": $.STORENUMBER,
"PROCESS_STATUS": $.PROCESS_STATUS
}) distinctBy $.STORENUMBER


output:



[
{
"OPERATING_COMPANY": "xx",
"STORE_CLOSING_TIME": [
"2019-01-03T22:00:00",
"2019-01-04T18:00:00"
],
"BATCH_ID": 1812,
"STORENUMBER": 1197,
"PROCESS_STATUS": "P"
},
{
"OPERATING_COMPANY": "xx",
"STORE_CLOSING_TIME": [
"2019-01-03T22:00:00",
"2019-01-04T18:00:00"
],
"BATCH_ID": 1314,
"STORENUMBER": 1198,
"PROCESS_STATUS": "P"
}
]





share|improve this answer


























  • updated the mapping

    – Anirban Sen Chowdhary
    Jan 3 at 23:14











  • Works just fine...thanks

    – Piyush Singh
    Jan 4 at 8:13














0












0








0







Try the following in dataweave:



%dw 1.0
%output application/json
%var time=(payload map $.STORE_CLOSING_TIME) distinctBy $.STORE_CLOSING_TIME
---
(payload map {

"OPERATING_COMPANY": $.OPERATING_COMPANY,
"STORE_CLOSING_TIME": time,
"BATCH_ID": $.BATCH_ID,
"STORENUMBER": $.STORENUMBER,
"PROCESS_STATUS": $.PROCESS_STATUS
}) distinctBy $.STORENUMBER


output:



[
{
"OPERATING_COMPANY": "xx",
"STORE_CLOSING_TIME": [
"2019-01-03T22:00:00",
"2019-01-04T18:00:00"
],
"BATCH_ID": 1812,
"STORENUMBER": 1197,
"PROCESS_STATUS": "P"
},
{
"OPERATING_COMPANY": "xx",
"STORE_CLOSING_TIME": [
"2019-01-03T22:00:00",
"2019-01-04T18:00:00"
],
"BATCH_ID": 1314,
"STORENUMBER": 1198,
"PROCESS_STATUS": "P"
}
]





share|improve this answer















Try the following in dataweave:



%dw 1.0
%output application/json
%var time=(payload map $.STORE_CLOSING_TIME) distinctBy $.STORE_CLOSING_TIME
---
(payload map {

"OPERATING_COMPANY": $.OPERATING_COMPANY,
"STORE_CLOSING_TIME": time,
"BATCH_ID": $.BATCH_ID,
"STORENUMBER": $.STORENUMBER,
"PROCESS_STATUS": $.PROCESS_STATUS
}) distinctBy $.STORENUMBER


output:



[
{
"OPERATING_COMPANY": "xx",
"STORE_CLOSING_TIME": [
"2019-01-03T22:00:00",
"2019-01-04T18:00:00"
],
"BATCH_ID": 1812,
"STORENUMBER": 1197,
"PROCESS_STATUS": "P"
},
{
"OPERATING_COMPANY": "xx",
"STORE_CLOSING_TIME": [
"2019-01-03T22:00:00",
"2019-01-04T18:00:00"
],
"BATCH_ID": 1314,
"STORENUMBER": 1198,
"PROCESS_STATUS": "P"
}
]






share|improve this answer














share|improve this answer



share|improve this answer








edited Jan 3 at 23:13

























answered Jan 3 at 22:36









Anirban Sen ChowdharyAnirban Sen Chowdhary

6,43442869




6,43442869













  • updated the mapping

    – Anirban Sen Chowdhary
    Jan 3 at 23:14











  • Works just fine...thanks

    – Piyush Singh
    Jan 4 at 8:13



















  • updated the mapping

    – Anirban Sen Chowdhary
    Jan 3 at 23:14











  • Works just fine...thanks

    – Piyush Singh
    Jan 4 at 8:13

















updated the mapping

– Anirban Sen Chowdhary
Jan 3 at 23:14





updated the mapping

– Anirban Sen Chowdhary
Jan 3 at 23:14













Works just fine...thanks

– Piyush Singh
Jan 4 at 8:13





Works just fine...thanks

– Piyush Singh
Jan 4 at 8:13




















draft saved

draft discarded




















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f54030303%2fconvert-array-of-json-into-single-json-with-inner-array%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







wQZDpmNb1 YKtkLW0wsBr4 tYLXVecE8
XAjBotzsU uNDVMF9uox3X,vGe,K4bcdUjU4qiPxo

Popular posts from this blog

Monofisismo

Angular Downloading a file using contenturl with Basic Authentication

Olmecas