Get initial JSON representation of ConfigurationSection

Assume this section is in appsettings.json

 { "crypto":{ "A": "some value", "B": "foo foo", "C": "last part" }, ... } 

Where "crypto" is a json serialization of some cryptographic key.

Later in the code I need to do something like this:

 var keyOptions = CryptoProvider.RestoreFromJson(Configuration.GetSection("crypto")) 

But Configuration.GetSection returns a ConfigurationSection instance. Is there any way to get raw json data?

I assumed that ConfigurationSection.Value should do the trick, but for some reason it is always null .

+7
json c # asp.net-core asp.net-core-mvc
source share
1 answer

If you want to get the contents of the crypto section, you can use Configuration.GetSection("crypto").AsEnumerable() (or for your example Configuration.GetSection("crypto").GetChildren() may be useful).

But the result is not raw json. You need to convert it.

0
source share

All Articles