I have a JSON as shown in below format:
{
"type": "AdaptiveCard",
"$schema": "http://adaptivecards.io/schemas/adaptive-card.json",
"version": "1.3",
"msteams": {
"width": "Full"
},
"body": [
{
"type": "TextBlock",
"text": "Select from below",
"wrap": true
},
{
"type": "TextBlock",
"text": " - **Mango**: Seasonal fruit available in summers and king of fruits.\n - **Apple**: available always and is considered to keep doctors away if you have them daily",
"wrap": true
},
{
"type": "ActionSet",
"actions": [
{
"type": "Action.ShowCard",
"title": "Mango",
"card": {
"type": "AdaptiveCard",
"body": [
{
"type": "ColumnSet",
"columns": [
{
"type": "Column",
"width": "stretch",
"items": [
{
"type": "Input.ChoiceSet",
"id": "staticID",
"isRequired": true,
"errorMessage": "Select a code to proceed",
"label": "Select a code:",
"choices": [
{
"title": "AE",
"value": "AE"
},
{
"title": "APPS1",
"value": "APPS1"
}
],
"placeholder": "Select one"
}
]
}
]
},
{
"type": "ColumnSet",
"columns": [
{
"type": "Column",
"width": "stretch",
"verticalContentAlignment": "Top",
"horizontalAlignment": "Left",
"items": [
{
"type": "Input.Text",
"placeholder": "Enter comments",
"id": "staticdlname",
"label": "Please enter your mango stories",
"isRequired": true,
"errorMessage": "Enter comment"
}
]
}
]
},
{
"type": "ActionSet",
"actions": [
{
"type": "Action.Submit",
"title": "Submit",
"data": {
"value": "staticdl"
}
}
]
}
]
}
},
{
"type": "Action.ShowCard",
"title": "Dynamic",
"card": {
"type": "AdaptiveCard",
"body": [
{
"type": "ColumnSet",
"columns": [
{
"type": "Column",
"width": "stretch",
"items": [
{
"type": "Input.ChoiceSet",
"id": "dynamicid",
"isRequired": true,
"errorMessage": "Select a code proceed",
"label": "Select a code:",
"choices": [
{
"title": "APAC",
"value": "APAC"
},
{
"title": "EU",
"value": "EU"
}
],
"placeholder": "Select one"
}
]
}
]
},
{
"type": "ColumnSet",
"columns": [
{
"type": "Column",
"width": "stretch",
"verticalContentAlignment": "Top",
"horizontalAlignment": "Left",
"items": [
{
"type": "Input.Text",
"placeholder": "Enter your apple stories",
"id": "dynamicdlname",
"label": "Enter a comment",
"isRequired": true,
"errorMessage": "Enter a comment"
}
]
}
]
},
{
"type": "ActionSet",
"actions": [
{
"type": "Action.Submit",
"title": "Submit",
"data": {
"value": "dynamicdl"
}
}
]
}
]
}
}
]
}
]
}
I would like to remove the entire node of "ActionSet" if the condition satisfies that type = "Action.Submit".
I tried below code:
var jtok = JToken.Parse(json);
var result = jtok["body"].Select(x => x["actions"]).ToList();
foreach(var item in result)
{
if(item != null)
{
item.Parent.Remove();
}
}
var output = jtok.ToString(Newtonsoft.Json.Formatting.Indented);
But I got error: "The parent is missing." This is the updated json which contains different types Action. From this i just need to delete nodes which contain Action.Submit.