@Junfeng Liang , you could try to use Json.Net to delete the specific element to generate two different json files.
Here is a code example you could refer to.
class Program
{
static void Main(string[] args)
{
Company company = new Company();
company.Name = "test1";
company.Employees = new List<Person>() { new Person() { ID = 1001, Name = "emp1" }, new Person() { ID = 1002, Name = "emp3" }, new Person() { ID = 1003, Name = "emp3" } };
string jsonString = JsonConvert.SerializeObject(company);
JObject jo = JObject.Parse(jsonString);
jo.Property("Employees").Remove();
string json1 = jo.ToString();
File.WriteAllText("test1.json", json1);
jo = JObject.Parse(jsonString);
jo.Property("Name").Remove();
string json2 = jo.ToString();
File.WriteAllText("test2.json", json2);
}
}
class Company
{
public string Name { get; set; }
public List<Person> Employees { get; set; }
}
class Person
{
public int ID { get; set; }
public string Name { get; set; }
}
Result:
If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".
Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.