You can convert the JSON string into a JSON Object and then use <your_field>.remove()
and get the updated JSON back by converting it back to string.
Below is a small example which demonstrates this:
import org.json.JSONException;
import org.json.JSONObject;
import java.util.ArrayList;
class Scratch {
public static void main(String[] args) throws JSONException {
String json = "{\n" +
" \"notice\": \"The Settings are updated successfully.\",\n" +
" \"settings\": {\n" +
" \"push_notification\": {\n" +
" \"enabled\": true,\n" +
" \"credentials\": [\n" +
" {\n" +
" \"key\": \"value\"\n" +
" }\n" +
" ],\n" +
" \"service_name\": \"API Testing\"\n" +
" },\n" +
" \"created_at\": \"2019-05-04T14:52:32.773Z\",\n" +
" \"deleted_at\": \"false\",\n" +
" \"updated_at\": \"2019-05-07T11:23:22.781Z\"\n" +
" " +
"}\n" +
"}";
// Create a JSON object from the json string
JSONObject jsonObject = new JSONObject(json);
// Get the object which needs to be manipulated
JSONObject settings = jsonObject.getJSONObject("settings");
// Add the attributes which needs to be removed as a list
ArrayList<String> keysToRemove = new ArrayList<>();
keysToRemove.add("created_at");
keysToRemove.add("deleted_at");
keysToRemove.add("updated_at");
// Iterate for the all the keys to remove
for (String key : keysToRemove) {
// Remove the field from the JSON
settings.remove(key);
}
System.out.println(jsonObject.toString());
}
}
Output:
{"settings":{"push_notification":{"credentials":[{"key":"value"}],"service_name":"API Testing","enabled":true}},"notice":"The Settings are updated successfully."}
response.where(r => r.Data["deleted_at"] == false).single();
(no guarantees on syntax or casing, I'm doing this ad hoc) is much easier than trying to mess with regex or string manipulation.