Json config

Hello, I believe this is the right category.

 

I'm working on a rust plugin with a config.

How can I create a system that generates a config that looks like this:

 

{
    "commands": [
        {
            "name": "help",
            "type": "text",
"respone": "Rule 1. No cheating.", }, { "name": "ping", "type": "ping",
"respone": "generatedResponse", } ] }

just look at any other plugin that has a config , see how they did it.

Hello, I think this could help you

        private class Command 
        {
            public string name;
            public string type;
            public string response;
        }

        private class PluginConfig
        {
            public List<Command> commands = new List<Command>();
        }
        private PluginConfig _config;

        protected override void SaveConfig() => Config.WriteObject(_config, true);
        protected override void LoadDefaultConfig()
        {
            _config = new PluginConfig();
            // Your examples
            _config.commands.Add(new Command()
            {
                name = "help" ,
                type = "text",
                response = "Rule 1. No cheating."
            });
            _config.commands.Add(new Command()
            {
                name = "ping",
                type = "ping",
                response = "generatedResponse"
            });
            SaveConfig();
        }
        protected override void LoadConfig()
        {
            base.LoadConfig();
            try
            {
                _config = Config.ReadObject<PluginConfig>();

                if (_config == null)
                    throw new Exception();

                SaveConfig(); // override posible obsolet / outdated config
            }
            catch (Exception)
            {
                PrintError("Loaded default config.");

                LoadDefaultConfig();
            }
        }

Output:

{
  "commands": [
    {
      "name": "help",
      "type": "text",
      "response": "Rule 1. No cheating."
    },
    {
      "name": "ping",
      "type": "ping",
      "response": "generatedResponse"
    }
  ]
}
Camoec

Hello, I think this could help you

        private class Command 
        {
            public string name;
            public string type;
            public string response;
        }

        private class PluginConfig
        {
            public List<Command> commands = new List<Command>();
        }
        private PluginConfig _config;

        protected override void SaveConfig() => Config.WriteObject(_config, true);
        protected override void LoadDefaultConfig()
        {
            _config = new PluginConfig();
            // Your examples
            _config.commands.Add(new Command()
            {
                name = "help" ,
                type = "text",
                response = "Rule 1. No cheating."
            });
            _config.commands.Add(new Command()
            {
                name = "ping",
                type = "ping",
                response = "generatedResponse"
            });
            SaveConfig();
        }
        protected override void LoadConfig()
        {
            base.LoadConfig();
            try
            {
                _config = Config.ReadObject<PluginConfig>();

                if (_config == null)
                    throw new Exception();

                SaveConfig(); // override posible obsolet / outdated config
            }
            catch (Exception)
            {
                PrintError("Loaded default config.");

                LoadDefaultConfig();
            }
        }

Output:

{
  "commands": [
    {
      "name": "help",
      "type": "text",
      "response": "Rule 1. No cheating."
    },
    {
      "name": "ping",
      "type": "ping",
      "response": "generatedResponse"
    }
  ]
}

Thank you! I will test this out tonight.