If id value is 0 then i don’t want that in output. Photos Array is dynamic in nature. Here it is 3 , it can be 3 or 4 or5 any . Your help in this is highly appreciated . thanks .
input JSON
{
"Entity": {
"card": {
"cardNo": "123456789",
"cardStatus": "10",
"cardAddress": "UK",
"cardAddress1": "US",
"cardCity": "mk",
"name": "RAM",
"lastName": "ABU",
"name1": "RAM1",
"lastName1": "ABU1",
"Id1": "0",
"Id2": 0,
"Id3": 0
},
"Photos": [
{
"Id": 327703,
"Caption": "TEST>> photo 1",
"Url": "http://bob.com/0001/327703/photo.jpg"
},
{
"Id": 327704,
"Caption": "TEST>> photo 2",
"Url": "http://bob.com/0001/327704/photo.jpg"
},
{
"Id": 327704,
"Caption": "TEST>> photo 2",
"Url": "http://bob.com/0001/327704/photo.jpg"
}
]
}
}
output JSON
{
"tab": {
"text": "123456789"
},
"address": [
{
"add": "UK",
"add2": "US",
"mk": "mk"
}
],
"Photos": [
{
"caption2": "http.1.com",
"no": "0"
},
{
"caption2": "http.2.com",
"no": "0"
},
{
"caption2": "http.3com",
"no": "0"
},
{
"caption2": "TEST>> photo 1",
"no": "327703"
},
{
"caption2": "TEST>> photo 2",
"no": "327704"
},
{
"caption2": "TEST>> photo 2",
"no": "327704"
}
]
}
expected JSON
{
"tab": {
"text": "123456789"
},
"address": [
{
"add": "UK",
"add2": "US",
"mk": "mk"
}
],
"Photos": [
{
"caption2": "TEST>> photo 1",
"no": "327703"
},
{
"caption2": "TEST>> photo 2",
"no": "327704"
},
{
"caption2": "TEST>> photo 2",
"no": "327704"
}
]
}
jolt spec using
[
{
"operation": "shift",
"spec": {
"Entity": {
"card": {
"cardNo": "tab.text",
"cardAddress": "address[0].add",
"cardAddress1": "address[0].add2",
"cardC*": "address[0].mk",
"Id1": "Photos.no",
"#http.1.com": "Photos.caption2",
"Id2": "Photos.no",
"#http.2.com": "Photos.caption2",
"Id3": "Photos.no",
"#http.3com": "Photos.caption2"
},
"Photos": {
"*": {
"Id": "Photos.no",
"Caption": "Photos.caption2"
}
}
}
}
},
{
"operation": "shift",
"spec": {
"tab": "&",
"address": "&",
"Photos": {
"*": {
"*": {
"@": "&3[&1].&2"
}
}
}
}
},
{
"operation": "modify-overwrite-beta",
"spec": {
"Photos": {
"*": {
"no": "=toString"
}
}
}
}
]
I am thinking one if else logic is required if value is 0 then don’t pass otherwise pass like that.
3
Answers
Hey Saurabh I couldn’t understand your request properly but this may help you resolve your query. I have created an spec for your expected output, I have kept an if else condition on Photos[].no if its 0 it wont populate the fields, you can check the below spec and input :
Input :
Spec :
You can start by converting the independent attributes dynamically collect under common nodes, then use conditional logic such as
You may consider another library Josson to do the same job by shorter transformation statement.
https://github.com/octomix/josson
Deserialization
Transformation
Output