Either Newtonsoft or the new System.Text.Json should be able to parse Json no matter how nested.
What you need to do is create classes which match the structure and hierarchy.
For example:
class Role
{
string Name { get; set; }
}
class Employee
{
string EmployeeName { get; set; }
Role Role { get; set; }
}
var json= JsonSerializer.Serialize<Employee>(employee);
should create something like
{
"Employee" :
{
"EmployeeName": "Bob",
"Role" : {
"Name": "Sales"
}
}
}
Please don't forget to click Accepted Answer and Upvote whenever the information provided helps you. Original posters help the community find answers faster by identifying the correct answer.