Nucs / JsonSettings

This library simplifies creating configuration for your C# app/service by utilizing the serialization capabilities of Json.NET to serialize nested (custom) objects, dictionaries and lists as simply as by creating a POCO and inheriting JsonSettings class.
MIT License
76 stars 18 forks source link

Nested data #11

Closed Terrijoo closed 5 years ago

Terrijoo commented 5 years ago

This might be a rather noobish question, but is there a way of writing/reading nested data? Something like:

{
  "Data": {
    "$type": "nucs.Collections.SafeDictionary`2[[System.String, mscorlib],[System.Object, mscorlib]], nucs.JsonSettings",
    "Test1": {
      "Option1": true,
      "Option2": "Bla"
    },
    "Test2": {
      "Option1": false,
      "Option2": "Another bla"
    }
  }
}
Nucs commented 5 years ago

If your intend is to read Test1 or Test2 without parsing it using this library then you can use newtonsoft.json to do that as it is the backend serialization I used in this library. see: https://dotnetfiddle.net/Kjcgmp

Did I understand your question correctly?

Terrijoo commented 5 years ago

That actually helped a bunch! Thanks!

Nucs commented 5 years ago

Also, I forgot to note that the library uses custom settings for conversion via newtonsoft.json. If you intend to convert/parse the json into an c# object outside of the library, make sure to set the library's custom settings. See here how to set the settings as default