I have a simple nested response using object property not model.
I want to change response json object to snake case
I have tried to convert using SnakeCaseNamingStrategy but still failed or nothing change at all
I hope someone can Help me, Thanks
{"PartnerInquiryId":"0f8e0a8a9fcf427ca5e534084c63bc91","ClientNumber":"04263123010394","ProductCode":"string","ResponseCode":"00","Message":"Success","DueDate":"21/01/2023","BillGenerationDate":"","IsOpenAmount":"","AdminFee":"2225","TotalAmount":"220225","Timestamp":"2023-05-05","BillDetails":[{"Name":"Customer Name","Value":"RIZA SAPTO PUTRO","IsPii":true,"IsShow":true},{"Name":"Bill To","Value":"1","IsPii":false,"IsShow":true},{"Name":"Penalty","Value":"0","IsPii":false,"IsShow":true},{"Name":"Interest","Value":"0","IsPii":false,"IsShow":true},{"Name":"Installment","Value":"0","IsPii":false,"IsShow":true}]}
the result is :
{
"PartnerInquiryId": "0f8e0a8a9fcf427ca5e534084c63bc91",
"ClientNumber": "04263123010394",
"ProductCode": "string",
"ResponseCode": "00",
"Message": "Success",
"DueDate": "21/01/2023",
"BillGenerationDate": "",
"IsOpenAmount": "",
"AdminFee": "2225",
"TotalAmount": "220225",
"Timestamp": "2023-05-05",
"BillDetails": [
{
"Name": "Customer Name",
"Value": "RIZA SAPTO PUTRO",
"IsPii": true,
"IsShow": true
},
{
"Name": "Bill To",
"Value": "1",
"IsPii": false,
"IsShow": true
},
{
"Name": "Penalty",
"Value": "0",
"IsPii": false,
"IsShow": true
},
{
"Name": "Interest",
"Value": "0",
"IsPii": false,
"IsShow": true
},
{
"Name": "Installment",
"Value": "0",
"IsPii": false,
"IsShow": true
}
]
}
public static string StringTOSnakeCaseNested(object str)
{
var obj = JsonConvert.DeserializeObject<object>((string)str);
var settings = new JsonSerializerSettings
{
ContractResolver = new DefaultContractResolver
{
NamingStrategy = new SnakeCaseNamingStrategy { ProcessDictionaryKeys = true }
},
Formatting = Formatting.Indented
};
var json = JsonConvert.SerializeObject(obj, settings);
return json;
}