Convert array of json into single json with inner array

Multi tool use
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty{ height:90px;width:728px;box-sizing:border-box;
}
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
add a comment |
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
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
add a comment |
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
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
mule dataweave
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
add a comment |
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
add a comment |
1 Answer
1
active
oldest
votes
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"
}
]
updated the mapping
– Anirban Sen Chowdhary
Jan 3 at 23:14
Works just fine...thanks
– Piyush Singh
Jan 4 at 8:13
add a comment |
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
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
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"
}
]
updated the mapping
– Anirban Sen Chowdhary
Jan 3 at 23:14
Works just fine...thanks
– Piyush Singh
Jan 4 at 8:13
add a comment |
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"
}
]
updated the mapping
– Anirban Sen Chowdhary
Jan 3 at 23:14
Works just fine...thanks
– Piyush Singh
Jan 4 at 8:13
add a comment |
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"
}
]
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"
}
]
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
add a comment |
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
add a comment |
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.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
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
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