C#C
C#3y ago
Kyede

Update JSON File with new values without overwriting existing data

Hello,

So I'm currently developing a Discord bot that stores values such as 'settings' for each guild. I already got that part figured out very well but I would like to know how I should handle additions / removes.

I have a class as followed:
        public class GuildConfiguration
        {
            public string GuildPrefix { get; set; } = default!;
            public bool EnableModeratorNotifications { get; set; } = default!;
            public GuildCommandPermissions GuildCommandPermissions { get; set; } = default!;
        }


As an example, currently, the json file doesn't have the public bool EnableModeratorNotifications included but it is a new feature I would like to add. If I add that to my class, how would I serialize it into the json file with a default value like true/false without overwriting the existing values there?
Was this page helpful?