Avalados por :
Hi Experts,
Tengo un cuerpo JSON en el que los registros de empleados pueden aparecer varias veces. Ahora, necesito eliminar el Elemento Raíz - EmployeeRecords e insertar "[". Por favor, sugiera.
JSON Fuente
{"EmployeeRecords":{
"PersonInformation":{
"EmailAddress":"[email protected]",
"Name":{
"FirstName":"Fabian",
"MiddleName":"null",
"LastName":"KOEHLMANN",
},
"Address":{
"AddressLine1":"Berlin GmbH",
"AddressLine2":"Erasmusstraße 20,,,,,",
"City":"DEU-BRLN",
"StateProvince":"DEU",
},
"employeeInformation":{
"DateHired":"09/29/2021",
"TerminationDate":"",
"JobRole":{
"JobTitle":"Specialist IT Security & Infrastructure",
"Department":"Finance - IT",
"IsCreateDepartment":"null",
},
"EmploymentStatus":"Active"
},
"IsUser":"true",
"UserInformation":{
"UserId":"7fa1785f-f4f3-42b5-96bd-33f195521635",
"Status":"Active",
"Locations":[
{
"Scope":"Berlin GmbH",
}
]
},
"RecordUid":"7fa1785f-f4f3-42b5-96bd-33f195521635",
"Id":"B0451412"
},
"EmployeeRecords":{
"PersonInformation":{
"EmailAddress":"[email protected]",
"Name":{
"FirstName":"Mirko",
"MiddleName":"null",
},
"Address":{
"AddressLine1":"",
"AddressLine2":"Industriestrasse 69,,,,,",
"City":"DEU-FEUC",
},
"DateOfBirth":"null",
"GenderType":"null",
},
"employeeInformation":{
"DateHired":"",
"TerminationDate":"",
"JobRole":{
"JobTitle":"",
"Department":"Production",
"IsCreateDepartment":"null",
},
"EmploymentStatus":"Active"
},
"IsUser":"true",
"UserInformation":{
"UserId":"4a8fd80b-27ea-400a-afdf-6a07a752a529",
"Locations":[
{
"Scope":"",
}
]
},
"RecordUid":"4a8fd80b-27ea-400a-afdf-6a07a752a529",
"Id":"A0282548"
}
}
JSON Objetivo debería ser
[
{
"PersonInformation":{
"EmailAddress":"[email protected]",
"Name":{
------------
- - - -
},
"RecordUid":"4a8fd80b-27ea-400a-afdf-6a07a752a529",
"Id":"A0282548"
}
]
Gracias.. Trabajando.. Muy apreciado
Hola Arvik,
Puedes probar con el siguiente código.
import com.sap.gateway.ip.core.customdev.util.Message
import groovy.json.*
def Message processData(Message message) {
def input = message.getBody(String)
def json = new JsonSlurper().parseText(input)
def builder = new groovy.json.JsonBuilder(
[
json.EmployeeRecords
]
)
message.setBody(builder.toPrettyString())
return message
}
Saludos,
Priyanka
Hola Arvik,
En primer lugar, el JSON fuente no es un JSON adecuado, ya que el atributo "EmployeeRecords" aparece varias veces. Un JSON no debería tener el mismo atributo repetido múltiples veces en el mismo nivel.
Saludos,
Lalit
© 2025 Copyright. Todos los derechos reservados.
Desarrollado por Prime Institute