我想替换一个JSON领域-Json Strings
[{"RoleName": "Normal User","ModuleName": "Calendar Management"},
{"RoleName": "Reporter","ModuleName": "Incident Management"},
{"RoleName": "Viewer","ModuleName": "ESG"},
{"RoleName": "Viewer","ModuleName": "Apps"}]
源json json hody
{“ personInformation”:{“ emailAddress”:“ ” ,“名称”:{“ firstName”:“ fabian”,“ lastname”:“ koehlmann”,“ preferredname”:“fabiankã¶hlmann”},address“:{” adversionLine1“:” berllin gmbh“ “:”eRasmusstraã²20,,,,,“邮政编码”:“ 10553”},“员工信息”:{“ losplyepy型”:“内部”,“ homploymentStatus”:“ active”,“ active”,“ jobrole”,“ jobrole”:{“decr疑:“财务 - it”,“ isCreateDepartment”:“ null”,“ jobtitle”:“专家IT安全& Infrastructure”,“ susterisorid”:“ null”,“ startdate”:“ 09/29/2021”,“ “:“ null”},“位置”:“柏林GmbH”,“职业”:“ null”},“ Isuser”:“ true”,“ userInformation”:{“ userId”:“ 7FA1785F-F4F4F3-42B5-96BD -33F195521635“,“状态”:“活动”,“位置”:{“ scope”:“ trn-loc”,“角色”,“ jsontoreplace”}},“ recorduid”:“ 2022/05/27”,“ id“:” A0201412“}}}
groovy脚本
def Message processData(Message message) {
def body = message.getBody(java.lang.String) as String;
def jsonSlurper = new JsonSlurper()
def SourceBody = jsonSlurper.parseText(body)
def ReplaceData = jsonSlurper.parseText('[{"RoleName": "Normal User","ModuleName":
"Calendar Management"},{"RoleName": "Reporter","ModuleName": "Incident Management"},
{"RoleName": "Viewer","ModuleName": "ESG"},{"RoleName": "Viewer","ModuleName":
"Apps"}]')
body = body.replaceAll('JSONtoReplace','ReplaceData');
message.setBody(body);
return message;
}
I want to replace a JSON field - JSONtoReplace by the below JSON strings
[{"RoleName": "Normal User","ModuleName": "Calendar Management"},
{"RoleName": "Reporter","ModuleName": "Incident Management"},
{"RoleName": "Viewer","ModuleName": "ESG"},
{"RoleName": "Viewer","ModuleName": "Apps"}]
Source JSON BODY
{"PersonInformation":{"EmailAddress":"[email protected]","Name":{"FirstName":"Fabian","LastName":"KOEHLMANN","PreferredName":"Fabian Köhlmann"},"Address":{"AddressLine1":"Berlin GmbH","AddressLine2":"Erasmusstraße 20,,,,,","PostalCode":"10553"},"employeeInformation":{"EmployeeType":"internal","EmploymentStatus":"Active","JobRole":{"Department":"Finance - IT","IsCreateDepartment":"null","JobTitle":"Specialist IT Security & Infrastructure","SupervisorId":"null","StartDate":"09/29/2021","EffectiveDate":"null"},"Location":"Berlin GmbH","Occupation":"null"},"IsUser":"true","UserInformation":{"UserId":"7fa1785f-f4f3-42b5-96bd-33f195521635","Status":"active","Locations":{"Scope":"TRN-LOC","Roles":"JSONtoReplace"}},"RecordUid":"2022/05/27","Id":"A0201412"}}
Groovy Script
def Message processData(Message message) {
def body = message.getBody(java.lang.String) as String;
def jsonSlurper = new JsonSlurper()
def SourceBody = jsonSlurper.parseText(body)
def ReplaceData = jsonSlurper.parseText('[{"RoleName": "Normal User","ModuleName":
"Calendar Management"},{"RoleName": "Reporter","ModuleName": "Incident Management"},
{"RoleName": "Viewer","ModuleName": "ESG"},{"RoleName": "Viewer","ModuleName":
"Apps"}]')
body = body.replaceAll('JSONtoReplace','ReplaceData');
message.setBody(body);
return message;
}
发布评论
评论(1)
您可以做这样的事情:
输出:
You can do something like this:
The output: