12

How to define environment variables in the app settings of an azure app service to override a list such as the following?

"reportsSettings": {
    "emails": [
      "a@gmail.com",
      "b@gmail.com",
      "c@gmail.com"
    ]
}

ps: I know I could turn the list into a string with a separator that my code would split like

"reportsSettings": {
    "emails": "a@gmail.com",b@gmail.com,c@gmail.com"
}

and then use an environment variable defined like that: key => reportsSettings:emails value => a@gmail.com",b@gmail.com,c@gmail.com

but I'm trying to see I can keep the json as a list.

Tseng
  • 61,549
  • 15
  • 193
  • 205
François
  • 3,164
  • 25
  • 58
  • You're right it is a duplicate. Strange as I **always** look at SOF suggestions before posting the question. Tks for pointing it out. – François Aug 01 '18 at 07:13
  • Please don't stuff question title with tags, that's what the tag section is for. Have a read on [What are tags, and how should I use them?](https://stackoverflow.com/help/tagging) on how to correctly use tags – Tseng Aug 01 '18 at 07:54
  • yes and no. SOF uses my question's title to suggest other questions to avoid duplicate. The title after your edit doesn't even mention Azure. – François Aug 01 '18 at 11:13

1 Answers1

20

You can do this by appending the index after the key:

reportsSettings:emails:0      ===>    a@gmail.com
reportsSettings:emails:1      ===>    b@gmail.com
reportsSettings:emails:2      ===>    c@gmail.com

Here how it looks like in the portal

enter image description here

Martin Brandl
  • 56,134
  • 13
  • 133
  • 172
  • What if the value is an object? – yosbel Aug 15 '19 at 17:15
  • I dont get your question? I expect you mean the value is a json (that represents an object). There might be a limit of characters you can specfiy here so you should keep that in mind. However, I doubt its a good practice to store any types of objects in application settings... – Martin Brandl Aug 15 '19 at 17:27
  • Yep, @Martin Brandl, if the value is a json, then it would not work, the value will not be bounded to the object of the setting in Aspnet. What I was able to do was to bind it to a string and then *deserialize* it manually. Thanks – yosbel Aug 19 '19 at 15:36