I have an below JSON input :
{
"data": [
{
"accessCriterias": [
{
"name": "level1",
"id": "1234"
}
],
"userRoleGroups": [
{
"name": "all_grp",
"id": "456"
},
{
"name": "read_only_grp",
"id": "234"
}
],
"firstName": "first_name_1"
},
{
"accessCriterias": [],
"userRoleGroups": [],
"firstName": "first_name_2"
},
{
"firstName": "first_name_3"
}
],
"next": true
}
I want below output:
{
"data" : [ {
"firstName" : "first_name_1",
"userRoleGroups" : [ {
"name" : "all_grp",
"id" : "456"
}, {
"name" : "read_only_grp",
"id" : "234"
} ],
"accessCriterias" : [ {
"name" : "level1",
"id" : "1234"
} ]
}, {
"firstName" : "first_name_2",
"userRoleGroups" : [ ],
"accessCriterias" : [ ]
}, {
"firstName" : "first_name_3",
"userRoleGroups" : [ ],
"accessCriterias" : [ ]
} ],
"next" : true,
"nextOffset" : 50
}
Output format :
(i) If userRoleGroups
and accessCriterias
fields values are blank (i.e. empty array) (like in 2nd JSON object in input) OR if these two fields are not present itself (like in 3rd JSON object in input), then in the output userRoleGroups
and accessCriterias
fields value should come as empty array i.e. [].
(ii) For userRoleGroups
and accessCriterias
only ‘name’ should come in output and not ‘id’
I tried below JOLT and I am able to achieve the 1st point of Output format but not able to achieve the 2nd point of Output format. I don’t want ‘id’ from the output.
[
{
"operation": "modify-default-beta",
"spec": {
"data": {
"*": {
"userRoleGroups": [],
"accessCriterias": []
}
}
}
},
{
"operation": "modify-overwrite-beta",
"spec": {
"data": {
"*": {
"size_userRoleGroups": "=size(@(1,userRoleGroups))",
"size_accessCriterias": "=size(@(1,accessCriterias))"
}
}
}
},
{
"operation": "shift",
"spec": {
"data": {
"*": {
"firstName": "data[&1].firstName",
"size_userRoleGroups": {
"*": {
"@2,userRoleGroups": "data[&3].userRoleGroups"
}
},
"size_accessCriterias": {
"*": {
"@2,accessCriterias": "data[&3].accessCriterias"
}
}
}
},
"next": "next"
}
},
{
"operation": "default",
"spec": {
"nextOffset": 50
}
}
]
Output I get from using above JOLT :
{
"data" : [ {
"firstName" : "first_name_1",
"userRoleGroups" : [ {
"name" : "all_grp",
"id" : "456"
}, {
"name" : "read_only_grp",
"id" : "234"
} ],
"accessCriterias" : [ {
"name" : "level1",
"id" : "1234"
} ]
}, {
"firstName" : "first_name_2",
"userRoleGroups" : [ ],
"accessCriterias" : [ ]
}, {
"firstName" : "first_name_3",
"userRoleGroups" : [ ],
"accessCriterias" : [ ]
} ],
"next" : true,
"nextOffset" : 50
}
Avinash Kumar is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.