Delete jObject/jToken from json

hello,

I need to delete single line (“shippingProfileId”: “”) from the below json.

{
“createTransactionRequest”: {
“merchantAuthentication”: {
“name”: “”,
“transactionKey”: “”
},
“transactionRequest”: {
“transactionType”: “authCaptureTransaction”,
“amount”: “”,
“profile”: {
“customerProfileId”: “”,
“paymentProfile”: { “paymentProfileId”: “” },
“shippingProfileId”: “”
},
“order”: {
“invoiceNumber”: “”,
“description”: “”
},
“tax”: {
“amount”: “”
},
“shipping”: {
“amount”: “”
},
“authorizationIndicatorType”: {
“authorizationIndicator”: “final”
}
}
}
}

thanks!

@Stefan_Germanov
Welcome to the forum

We assume that the JSON was deserialized:
grafik
output: myJObject

So we can remove the shippingProfileId Property by:

grafik
TargetObject:

myJObject.SelectToken("..profile").Value(of JObject).Property("shippingProfileId")

Hi @Stefan_Germanov

Try this:

Deserialize JSON
   - Input: Your JSON string

Assign
   - To: jsonData
   - Value: jsonNewtonsoft.Json.JsonConvert.DeserializeObject(Of Newtonsoft.Json.Linq.JObject)(Your JSON string)

Assign
   - To: jsonData.SelectToken("createTransactionRequest.transactionRequest.profile.shippingProfileId")
   - Value: Nothing

Assign
   - To: updatedJsonString
   - Value: jsonNewtonsoft.Json.JsonConvert.SerializeObject(jsonData, Newtonsoft.Json.Formatting.Indented)

Hope it helps!!

May we ask you to share with us a screenshot of this implemented step? Thanks

thanks!
Could you please explain how SelectToken path works?
image
In case there are multiple keys with value “profile” can we use specific path?

A JSON Path is used for the retrival
https://goessner.net/articles/JsonPath/

SelectToken - for a single return
SelectTokens - for a multi return

1 Like

This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.