I need to iterate the nested json and need to extract the few fixed attribute values from the final json object. In the below JSON, I need to do some internal logic for the title/ref and other attributes. How can I parse the below json and get the Keys like type,employeeFirstName,employeeLastName and address
JSON:
"properties": {
"type": {
"description": "Defines type of object being represented",
"type": "string",
"enum": [
"employee"
]
},
"employeeFirstName": {
"title": "First Name",
"description": "Employee first name",
"type": "string"
},
"employeeLastName": {
"title": "Last Name",
"description": "Employee Last name",
"type": "string"
},
"address": {
"title": "Address",
"description": "Employee present address ",
"$ref": "#/definitions/address"
}
}
Code:
var jsonObject = JObject.Parse(jsonFileContent);
var propertyContent = JObject.Parse(jsonObject["properties"].ToString());
var definitionContent = JObject.Parse(jsonObject["definitions"].ToString());
for (int i = 0; i < propertyContent.Count; i++)
{
// Here I need to pass the value dynamically.
//For Example, first iteration, type needs to be passed,
//in second iteration, employeeFirstName needs to be passed and so on
var tempContent = propertyContent["address"].ToString();
var def = JObject.Parse(tempContent);
for (int j = 0; j < def.Count; j++)
{
//Some working logic is added based on the specific key
}
}
In the above code, I need to pass the dynamic key in the step var tempContent = propertyContent["address"].ToString();
for each iteration .So, Is there any way to capture all the Keys from the propertyContent