Example
{
First name : abc
Last name : cde
Manager of : xxx
Member of : yyy
}
This is the sample JSON body . In this JSON body , either manager of or member of keys are only allowed. How to build a one dynamic JSON?
Eg : A can both member of and manager of keys
But whereas B can have only manager of key.
So for this scenario how to build one dynamic json to handle both ways.
Parvathy
(PS Parvathy)
January 9, 2024, 11:37am
2
Hi @Ragavi_Rajasekar
You can create dynamic JSON in below way:
{
"First name": "abc",
"Last name": "cde",
"Roles": {
"Manager of": ["xxx"],
"Member of": ["yyy"]
}
}
=> Entity A with both “Manager of” and “Member of” keys:
{
"First name": "A",
"Last name": "B",
"Roles": {
"Manager of": ["xxx"],
"Member of": ["yyy", "zzz"]
}
}
=> Entity B with only the “Manager of” key:
{
"First name": "B",
"Last name": "C",
"Roles": {
"Manager of": ["xxx"]
}
}
Hope it helps!!
No I want one json for both scenarios … is it possible ?
Parvathy
(PS Parvathy)
January 9, 2024, 12:11pm
4
Hi @Ragavi_Rajasekar
May be you could try this way:
Assign activity:
To: jsonString (String)
Value: "{""first_name"": ""abc"",""last_name"": ""cde"",""roles"": {" +
If(A_is_manager, """manager_of"": ""xxx""", "") +
If(A_is_manager And A_is_member, ",", "") +
If(A_is_member, """member_of"": ""yyy""", "") +
"}}"
A_is_manager and A_is_member are variables representing whether the person is a manager or a member. Adjust the conditions and values based on your specific requirements. The resulting jsonString will contain the appropriate keys based on the conditions you set.
Regards