I'm having trouble transforming a JSON response from an API.
Basically their API returns me a JSON objects with this format:
{
"data":{
"id":1000000,
"firstName":"John",
"lastName":"Doe",
"custom_186549":{
"name":"Pension_overenskomst",
"type":"Boolean",
"value":false
},
"custom_186550":{
"name":"Pension 1. arbejdsdag",
"type":"Boolean",
"value":false
}
}
}
Problem is that different employees will have different custom_XXXX names while they contain similar information.
In the picture you see custom_186549 contains information about "pension_overenskomst". But for another employee this might be inside custom_175134. I need to unify their format and get the sub fields of "pension_overenskomst" as the JSON object name and get rid of the custom elements.
I would like it to just say
{
"data":{
"id":1000000,
"firstName":"John",
"lastName":"Doe",
"Pension_overenskomst":false,
"Pension 1. arbejdsdag":false
}
}
Regardless of what "custom" element it's inside.
Update: Managed to get the elements into an array. Now I just need to find a way to append them back into the JSON string.
var response = await httpClient.SendAsync(request);
var content = await response.Content.ReadAsStringAsync();
var responseObj = JsonConvert.DeserializeObject<dynamic>(content).data;
JObject names = JObject.Parse(content);
IEnumerable<JToken> CustomColumnsNames = names.SelectTokens("$.data.*.name");
IEnumerable<JToken> CustomColumnValues = names.SelectTokens("$.data.*.value");