How to remove a property from JSON data in C Sharp

--

Description: Suppose we have the following JSON data and we want to remove the property “RunIsolated” (highlighted) under the compositeRequest to get the final JSON without this property:

How to remove a property from Json data in C Sharp
How to remove a property from Json data in C Sharp

Solution for Json:

Following is the sample code to achieve this:
string jsonContent = "{\"allOrNone\":false,\"compositeRequest\":[{\"method\":\"PATCH\",\"referenceId\":\"REF09095303b88a40708d737c10cdc01107\",\"body\":{\"RunIsolated\":false,\"XXXX__Account_Manager__c\":1}},{\"method\":\"PATCH\",\"referenceId\":\"REF1899153fa1964e7ea3d3efb523005724\",\"body\":{\"RunIsolated\":false,\"XXXX__Account_Manager__c\":2}},{\"method\":\"PATCH\",\"referenceId\":\"REF1899153fa1964e7ea3d3efb523005724\",\"body\":{\"RunIsolated\":false,\"XXXX__Account_Manager__c\":3}}]}";
dynamic jObj = JsonConvert.DeserializeObject(jsonContent);
foreach (var item in jObj.compositeRequest)
{
JObject header = (JObject)item.SelectToken("body");
header.Property("RunIsolated").Remove();
}
string json = jObj.ToString();

Final Output: From the screenshot, it can be seen, the property “RunIsolated” is removed in the final JSON now.

Webner Solutions is a Software Development company focused on developing Insurance Agency Management Systems, Learning Management Systems and Salesforce apps. Contact us at dev@webners.com for your Insurance, eLearning and Salesforce applications.

Originally published at https://blog.webnersolutions.com on August 2, 2021.

--

--

Webner Solutions
Webner Solutions

Written by Webner Solutions

Our team in Salesforce is very strong, with in-depth knowledge of Salesforce classic and Lightning development as well as the Service cloud.

No responses yet