Skip to content

if condition in array values #28

Open

Description

@khushboobansal1910

Hi,

I have a doubt. I am trying to do transformation.

Consider that my input data is like below :
var data = {
"balance":{
"amount": 100
},
"disposable":{
"amount":200
}
};

For the above data I want to create template such that it return me an array of balances which consists of objects having two attributes "balancetype" and "amount".
If data has balance then it should return me "balancetype":"interim" and "amount":"balance.amount" and if data has disposable then it should return me "balancetype":"extrim" and "amount":"disposable .amount" .
Note: If data has both balance and disposable then balances array should have two objects and if data has either of balance and disposable then balances array should have one object and if data is not having both of balance and disposable then balances array should not be returned.

Case 1:
var data = {
"name": "khushboo",
"balance":{
"amount": 100
},
"disposable":{
"amount":200
}
};

Expected Output:
{"balances":[
{ "balancetype":"interim",
"amount": 100
},
{ "balancetype":"extrim",
"amount": 200
}
]
}

Case 2:
var data = {
"name": "khushboo",
"balance":{
"amount": 100
}
};

Expected Output:
{"balances":[
{ "balancetype":"interim",
"amount": 100
}
]
}

Case 2:
var data = {
"name": "khushboo"
};

Expected Output:
{
}

Please help me in providing such a template.

Activity

  1. khushboobansal1910 commented on Oct 16, 2018

    @khushboobansal1910
    Author

    @gliechtenstein , @mihir83in Please help it's really urgent.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions