I have below input json:
[
{
"Validator": [
{
"name": "API_Automation_Client",
"guid": "8013091c-6f2e-46c4-b406-b11a4b78c628",
"status": "NOT PUBLISHED"
},
{
"name": "HNCServerTest",
"guid": "8a73c938-8687-4de2-9020-0a5bed37f91d",
"status": "NOT PUBLISHED"
},
{
"name": "Time",
"guid": "Time",
"status": "NOT PUBLISHED"
},
{
"name": "SV-p1",
"guid": "aa2a1f6a-165b-409b-978e-ee436d0ae81c",
"status": "NOT PUBLISHED"
}
],
"selectedRelease": {},
"Replay": [],
"entity": "Validator",
"publishedString": "SV-p1,Time,API_Automation_Client"
}
]
I am using json spec to convert it such that the status is "PUBLISHED" if the Validator name is present in publishedString otherwise the status remains as NOT PUBLISHED.
[
{
"operation": "shift",
"spec": {
"*": {
"Validator": {
"*": {
"name": "[0].Validator[&1].name",
"guid": "[0].Validator[&1].guid",
"status": "[0].Validator[&1].status"
}
},
"selectedRelease": "[0].selectedRelease",
"Replay": "[0].Replay",
"entity": "[0].entity",
"publishedString": "[0].publishedString"
}
}
},
{
"operation": "modify-overwrite-beta",
"spec": {
"*": {
"Validator": {
"*": {
"status": "=split(@(2,publishedString), ',').contains(@(0,name)) ? 'PUBLISHED' : 'NOT PUBLISHED'"
}
}
}
}
}
]
But it is giving status as NOT PUBLISHED for all Validators.
Please suggest.
Below is the output I am expecting:
2
Answers
If you split the "publishedString" by the value of the "name", you will get a list of size 2 or 1 according to the presence or absence of the "name" in the string, except if the "name" value is the latest, so I use the trick to add a dummy element at the end. Then it’s just a matter to generated the "status" according to the value of the size.
You can use the following transformations :