Skip to content

Instantly share code, notes, and snippets.

@felipebizz
Last active Aug 29, 2015
Embed
What would you like to do?
[Mule] Create JSON with Groovy from a payload Mule
<scripting:component doc:name="Groovy">
<scripting:script engine="Groovy"><![CDATA[
def list = [];
def issue = [:];
for(i = 0 ; i < payload.size(); i++){
issue.id = 'arizona.jobdone.processo.' + payload[i].JOB_ID + '-' + payload[i].PROCESS_ID;
issue.key = 'arizona.jobdone.processo.' + payload[i].JOB_ID + '-' + payload[i].PROCESS_ID;
issue.fields = [:];
issue.fields.summary = payload[i].JOB_ID + '|' + payload[i].PROCESS_ID + '| Desd.3 |' + payload[i].CLIENTE + '|' + payload[i].AGENCIA + '| capas | PRINT |' + payload[i].PROCESS_NAME
issue.fields.project = [:];
issue.fields.project.id = '1';
issue.fields.project.key = 'VSTC';
issue.fields.project.name = 'Time Central - JobDone';
list.add(issue);
}
def root = [:];
root.expand = 'schema,names';
root.startAt = 0;
root.maxResults = 500
root.total= 7
root.issues =[:];
root.issues = list
def jsonContent = new groovy.json.JsonBuilder(root);
println 'JSON COMPLETE : ' +jsonContent.toString()
return jsonContent.toPrettyString();
]]></scripting:script>
</scripting:component>
<!-- RESULT -->
{
expand: "schema,names",
startAt: 0,
maxResults: 500,
total: 7,
issues:
[
{
id: "arizona.jobdone.processo.34076-19",
key: "arizona.jobdone.processo.34076-19",
fields: {
summary: "34076|19| Desd.3 |BOTICARIO|ALMAP| capas | PRINT |Expedição",
project: {
id: "1",
key: "VSTC",
name: "Time Central - JobDone"
}
}
},
{
id: "arizona.jobdone.processo.34076-19",
key: "arizona.jobdone.processo.34076-19",
fields: {
summary: "34076|19| Desd.3 |BOTICARIO|ALMAP| capas | PRINT |Expedição",
project: {
id: "1",
key: "VSTC",
name: "Time Central - JobDone"
}
}
}
]
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment