Store and load function app settings as JSON object with C# and Azure Functions 2.xRe-Starting Poison blobs in Azure FunctionsSetting Azure Function app settings with VSTS without exposing in the Azure PortalHow to bind CloudStorageAccount input to Azure Function?Missing value for AzureWebJobsStorage in local.settings.json local development in Visual Studio 2017Azure function implemented locally won't work in the cloudAdding connection settings during runtime for Azure Function AppWhy is GetEnvironmentVariable recommended to use over AppSettings when reading Environment variables in Azure FunctionsAzure function is giving not a valid Base-64 string errorCorrect use of app and local settings with Azure Function Bindings?Azure Functions log is always null
Showing mass murder in a kid's book
Anime with legendary swords made from talismans and a man who could change them with a shattered body
Storage of electrolytic capacitors - how long?
Giving feedback to someone without sounding prejudiced
Why can't the Brexit deadlock in the UK parliament be solved with a plurality vote?
El Dorado Word Puzzle II: Videogame Edition
Identifying "long and narrow" polygons in with PostGIS
Alignment of six matrices
How to make money from a browser who sees 5 seconds into the future of any web page?
How do I tell my boss that I'm quitting in 15 days (a colleague left this week)
Mimic lecturing on blackboard, facing audience
Given this phrasing in the lease, when should I pay my rent?
Deciphering cause of death?
Quoting Keynes in a lecture
Is there anyway, I can have two passwords for my wi-fi
What is the smallest number n> 5 so that 5 ^ n ends with "3125"?
Check if object is null and return null
Proving an identity involving cross products and coplanar vectors
Overlapping circles covering polygon
I'm just a whisper. Who am I?
Should I warn a new PhD Student?
Should I assume I have passed probation?
How do I fix the group tension caused by my character stealing and possibly killing without provocation?
Determining multivariate least squares with constraint
Store and load function app settings as JSON object with C# and Azure Functions 2.x
Re-Starting Poison blobs in Azure FunctionsSetting Azure Function app settings with VSTS without exposing in the Azure PortalHow to bind CloudStorageAccount input to Azure Function?Missing value for AzureWebJobsStorage in local.settings.json local development in Visual Studio 2017Azure function implemented locally won't work in the cloudAdding connection settings during runtime for Azure Function AppWhy is GetEnvironmentVariable recommended to use over AppSettings when reading Environment variables in Azure FunctionsAzure function is giving not a valid Base-64 string errorCorrect use of app and local settings with Azure Function Bindings?Azure Functions log is always null
App settings below is stored and read like below:
Stored:
local.settings.json
"IsEncrypted": false,
"Values":
"AzureWebJobsStorage": "UseDevelopmentStorage=true",
"FUNCTIONS_WORKER_RUNTIME": "dotnet",
"Car_Id": "id",
"Car_Name": "name"
Loaded:
GetEnvironmentVariable("Car_Id");
private static string GetEnvironmentVariable(string name)
return (string)System.Environment.GetEnvironmentVariables(EnvironmentVariableTarget.Process)[name];
Is it possible to store the settings as object and load it into an object?
local.settings.json
"IsEncrypted": false,
"Values":
"AzureWebJobsStorage": "UseDevelopmentStorage=true",
"FUNCTIONS_WORKER_RUNTIME": "dotnet"
Car:
"Id": "id",
"Name": "name"
class Car
public int Id get;set;
public string Name get;set;
Visual studio 2017
Udpate
The solution needs to be compitable with the settings on Azure Function App settings. That is, can the settings on local.settngs.json be saved on Azure Function app settings?
add a comment |
App settings below is stored and read like below:
Stored:
local.settings.json
"IsEncrypted": false,
"Values":
"AzureWebJobsStorage": "UseDevelopmentStorage=true",
"FUNCTIONS_WORKER_RUNTIME": "dotnet",
"Car_Id": "id",
"Car_Name": "name"
Loaded:
GetEnvironmentVariable("Car_Id");
private static string GetEnvironmentVariable(string name)
return (string)System.Environment.GetEnvironmentVariables(EnvironmentVariableTarget.Process)[name];
Is it possible to store the settings as object and load it into an object?
local.settings.json
"IsEncrypted": false,
"Values":
"AzureWebJobsStorage": "UseDevelopmentStorage=true",
"FUNCTIONS_WORKER_RUNTIME": "dotnet"
Car:
"Id": "id",
"Name": "name"
class Car
public int Id get;set;
public string Name get;set;
Visual studio 2017
Udpate
The solution needs to be compitable with the settings on Azure Function App settings. That is, can the settings on local.settngs.json be saved on Azure Function app settings?
add a comment |
App settings below is stored and read like below:
Stored:
local.settings.json
"IsEncrypted": false,
"Values":
"AzureWebJobsStorage": "UseDevelopmentStorage=true",
"FUNCTIONS_WORKER_RUNTIME": "dotnet",
"Car_Id": "id",
"Car_Name": "name"
Loaded:
GetEnvironmentVariable("Car_Id");
private static string GetEnvironmentVariable(string name)
return (string)System.Environment.GetEnvironmentVariables(EnvironmentVariableTarget.Process)[name];
Is it possible to store the settings as object and load it into an object?
local.settings.json
"IsEncrypted": false,
"Values":
"AzureWebJobsStorage": "UseDevelopmentStorage=true",
"FUNCTIONS_WORKER_RUNTIME": "dotnet"
Car:
"Id": "id",
"Name": "name"
class Car
public int Id get;set;
public string Name get;set;
Visual studio 2017
Udpate
The solution needs to be compitable with the settings on Azure Function App settings. That is, can the settings on local.settngs.json be saved on Azure Function app settings?
App settings below is stored and read like below:
Stored:
local.settings.json
"IsEncrypted": false,
"Values":
"AzureWebJobsStorage": "UseDevelopmentStorage=true",
"FUNCTIONS_WORKER_RUNTIME": "dotnet",
"Car_Id": "id",
"Car_Name": "name"
Loaded:
GetEnvironmentVariable("Car_Id");
private static string GetEnvironmentVariable(string name)
return (string)System.Environment.GetEnvironmentVariables(EnvironmentVariableTarget.Process)[name];
Is it possible to store the settings as object and load it into an object?
local.settings.json
"IsEncrypted": false,
"Values":
"AzureWebJobsStorage": "UseDevelopmentStorage=true",
"FUNCTIONS_WORKER_RUNTIME": "dotnet"
Car:
"Id": "id",
"Name": "name"
class Car
public int Id get;set;
public string Name get;set;
Visual studio 2017
Udpate
The solution needs to be compitable with the settings on Azure Function App settings. That is, can the settings on local.settngs.json be saved on Azure Function app settings?
edited Mar 8 at 15:28
Pingpong
asked Mar 7 at 21:47
PingpongPingpong
2,394114498
2,394114498
add a comment |
add a comment |
2 Answers
2
active
oldest
votes
Is it possible to store the settings as object and load it into an object?
Yes, you could use the code as below to achieve it.
public static async Task<IActionResult> Car(
[HttpTrigger(AuthorizationLevel.Anonymous, "post", Route = "Car")]
HttpRequest httpRequest, ILogger log, ExecutionContext context)
log.LogInformation("C# HTTP trigger function processed a request.");
var config = new ConfigurationBuilder()
.SetBasePath(context.FunctionAppDirectory)
.AddJsonFile("local.settings.json", optional: true, reloadOnChange: true)
.AddEnvironmentVariables()
.Build();
var cars= new Car();
config.Bind("Car", cars);
var b = cars.Id.ToString();
log.LogInformation($"Car id is: b");
return (ActionResult)new OkObjectResult($"Hello, b");
The local.settings.json is as below:
"IsEncrypted": false,
"Values":
"AzureWebJobsStorage": "xxxxx",
"FUNCTIONS_WORKER_RUNTIME": "dotnet"
,
"Car":
"Id": "123456",
"Name": "name_1"
The Car class:
public class Car
public int Id get; set;
public string Name get; set;
The snapshot:

For more details, you could refer to this article.
Hope it helps you:)
Please see my update
– Pingpong
Mar 8 at 15:30
answered for the link
– Pingpong
Mar 10 at 23:43
add a comment |
You can follow the code below, and please point me out if I misunderstand you.
My local.settings.json file:
"IsEncrypted": false,
"Values":
"AzureWebJobsStorage": "xxxxx",
"FUNCTIONS_WORKER_RUNTIME": "dotnet"
,
"Car":
"Id": "123",
"Name": "name_1"
The Car.cs:
public class Car
public int Id get; set;
public string Name get; set;
public Car()
JObject jsonData = JObject.Parse(File.ReadAllText(Environment.CurrentDirectory+ @"local.settings.json"));
Id = Convert.ToInt32(jsonData.Root.SelectToken("Car")["Id"]);
Name = Convert.ToString(jsonData.Root.SelectToken("Car")["Name"]);
The run method in Function.cs:
[FunctionName("Function1")]
public static void Run([TimerTrigger("0 */1 * * * *")]TimerInfo myTimer, ILogger log)
log.LogInformation($"C# Timer trigger function executed at: DateTime.Now");
Car c = new Car();
log.LogInformation($"the id is: c.Id");
log.LogInformation($"the name is: c.Name");
The test result:

Please see my update
– Pingpong
Mar 8 at 15:30
add a comment |
Your Answer
StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");
StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);
else
createEditor();
);
function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55053325%2fstore-and-load-function-app-settings-as-json-object-with-c-sharp-and-azure-funct%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
Is it possible to store the settings as object and load it into an object?
Yes, you could use the code as below to achieve it.
public static async Task<IActionResult> Car(
[HttpTrigger(AuthorizationLevel.Anonymous, "post", Route = "Car")]
HttpRequest httpRequest, ILogger log, ExecutionContext context)
log.LogInformation("C# HTTP trigger function processed a request.");
var config = new ConfigurationBuilder()
.SetBasePath(context.FunctionAppDirectory)
.AddJsonFile("local.settings.json", optional: true, reloadOnChange: true)
.AddEnvironmentVariables()
.Build();
var cars= new Car();
config.Bind("Car", cars);
var b = cars.Id.ToString();
log.LogInformation($"Car id is: b");
return (ActionResult)new OkObjectResult($"Hello, b");
The local.settings.json is as below:
"IsEncrypted": false,
"Values":
"AzureWebJobsStorage": "xxxxx",
"FUNCTIONS_WORKER_RUNTIME": "dotnet"
,
"Car":
"Id": "123456",
"Name": "name_1"
The Car class:
public class Car
public int Id get; set;
public string Name get; set;
The snapshot:

For more details, you could refer to this article.
Hope it helps you:)
Please see my update
– Pingpong
Mar 8 at 15:30
answered for the link
– Pingpong
Mar 10 at 23:43
add a comment |
Is it possible to store the settings as object and load it into an object?
Yes, you could use the code as below to achieve it.
public static async Task<IActionResult> Car(
[HttpTrigger(AuthorizationLevel.Anonymous, "post", Route = "Car")]
HttpRequest httpRequest, ILogger log, ExecutionContext context)
log.LogInformation("C# HTTP trigger function processed a request.");
var config = new ConfigurationBuilder()
.SetBasePath(context.FunctionAppDirectory)
.AddJsonFile("local.settings.json", optional: true, reloadOnChange: true)
.AddEnvironmentVariables()
.Build();
var cars= new Car();
config.Bind("Car", cars);
var b = cars.Id.ToString();
log.LogInformation($"Car id is: b");
return (ActionResult)new OkObjectResult($"Hello, b");
The local.settings.json is as below:
"IsEncrypted": false,
"Values":
"AzureWebJobsStorage": "xxxxx",
"FUNCTIONS_WORKER_RUNTIME": "dotnet"
,
"Car":
"Id": "123456",
"Name": "name_1"
The Car class:
public class Car
public int Id get; set;
public string Name get; set;
The snapshot:

For more details, you could refer to this article.
Hope it helps you:)
Please see my update
– Pingpong
Mar 8 at 15:30
answered for the link
– Pingpong
Mar 10 at 23:43
add a comment |
Is it possible to store the settings as object and load it into an object?
Yes, you could use the code as below to achieve it.
public static async Task<IActionResult> Car(
[HttpTrigger(AuthorizationLevel.Anonymous, "post", Route = "Car")]
HttpRequest httpRequest, ILogger log, ExecutionContext context)
log.LogInformation("C# HTTP trigger function processed a request.");
var config = new ConfigurationBuilder()
.SetBasePath(context.FunctionAppDirectory)
.AddJsonFile("local.settings.json", optional: true, reloadOnChange: true)
.AddEnvironmentVariables()
.Build();
var cars= new Car();
config.Bind("Car", cars);
var b = cars.Id.ToString();
log.LogInformation($"Car id is: b");
return (ActionResult)new OkObjectResult($"Hello, b");
The local.settings.json is as below:
"IsEncrypted": false,
"Values":
"AzureWebJobsStorage": "xxxxx",
"FUNCTIONS_WORKER_RUNTIME": "dotnet"
,
"Car":
"Id": "123456",
"Name": "name_1"
The Car class:
public class Car
public int Id get; set;
public string Name get; set;
The snapshot:

For more details, you could refer to this article.
Hope it helps you:)
Is it possible to store the settings as object and load it into an object?
Yes, you could use the code as below to achieve it.
public static async Task<IActionResult> Car(
[HttpTrigger(AuthorizationLevel.Anonymous, "post", Route = "Car")]
HttpRequest httpRequest, ILogger log, ExecutionContext context)
log.LogInformation("C# HTTP trigger function processed a request.");
var config = new ConfigurationBuilder()
.SetBasePath(context.FunctionAppDirectory)
.AddJsonFile("local.settings.json", optional: true, reloadOnChange: true)
.AddEnvironmentVariables()
.Build();
var cars= new Car();
config.Bind("Car", cars);
var b = cars.Id.ToString();
log.LogInformation($"Car id is: b");
return (ActionResult)new OkObjectResult($"Hello, b");
The local.settings.json is as below:
"IsEncrypted": false,
"Values":
"AzureWebJobsStorage": "xxxxx",
"FUNCTIONS_WORKER_RUNTIME": "dotnet"
,
"Car":
"Id": "123456",
"Name": "name_1"
The Car class:
public class Car
public int Id get; set;
public string Name get; set;
The snapshot:

For more details, you could refer to this article.
Hope it helps you:)
answered Mar 8 at 6:14
Joey CaiJoey Cai
5,6751211
5,6751211
Please see my update
– Pingpong
Mar 8 at 15:30
answered for the link
– Pingpong
Mar 10 at 23:43
add a comment |
Please see my update
– Pingpong
Mar 8 at 15:30
answered for the link
– Pingpong
Mar 10 at 23:43
Please see my update
– Pingpong
Mar 8 at 15:30
Please see my update
– Pingpong
Mar 8 at 15:30
answered for the link
– Pingpong
Mar 10 at 23:43
answered for the link
– Pingpong
Mar 10 at 23:43
add a comment |
You can follow the code below, and please point me out if I misunderstand you.
My local.settings.json file:
"IsEncrypted": false,
"Values":
"AzureWebJobsStorage": "xxxxx",
"FUNCTIONS_WORKER_RUNTIME": "dotnet"
,
"Car":
"Id": "123",
"Name": "name_1"
The Car.cs:
public class Car
public int Id get; set;
public string Name get; set;
public Car()
JObject jsonData = JObject.Parse(File.ReadAllText(Environment.CurrentDirectory+ @"local.settings.json"));
Id = Convert.ToInt32(jsonData.Root.SelectToken("Car")["Id"]);
Name = Convert.ToString(jsonData.Root.SelectToken("Car")["Name"]);
The run method in Function.cs:
[FunctionName("Function1")]
public static void Run([TimerTrigger("0 */1 * * * *")]TimerInfo myTimer, ILogger log)
log.LogInformation($"C# Timer trigger function executed at: DateTime.Now");
Car c = new Car();
log.LogInformation($"the id is: c.Id");
log.LogInformation($"the name is: c.Name");
The test result:

Please see my update
– Pingpong
Mar 8 at 15:30
add a comment |
You can follow the code below, and please point me out if I misunderstand you.
My local.settings.json file:
"IsEncrypted": false,
"Values":
"AzureWebJobsStorage": "xxxxx",
"FUNCTIONS_WORKER_RUNTIME": "dotnet"
,
"Car":
"Id": "123",
"Name": "name_1"
The Car.cs:
public class Car
public int Id get; set;
public string Name get; set;
public Car()
JObject jsonData = JObject.Parse(File.ReadAllText(Environment.CurrentDirectory+ @"local.settings.json"));
Id = Convert.ToInt32(jsonData.Root.SelectToken("Car")["Id"]);
Name = Convert.ToString(jsonData.Root.SelectToken("Car")["Name"]);
The run method in Function.cs:
[FunctionName("Function1")]
public static void Run([TimerTrigger("0 */1 * * * *")]TimerInfo myTimer, ILogger log)
log.LogInformation($"C# Timer trigger function executed at: DateTime.Now");
Car c = new Car();
log.LogInformation($"the id is: c.Id");
log.LogInformation($"the name is: c.Name");
The test result:

Please see my update
– Pingpong
Mar 8 at 15:30
add a comment |
You can follow the code below, and please point me out if I misunderstand you.
My local.settings.json file:
"IsEncrypted": false,
"Values":
"AzureWebJobsStorage": "xxxxx",
"FUNCTIONS_WORKER_RUNTIME": "dotnet"
,
"Car":
"Id": "123",
"Name": "name_1"
The Car.cs:
public class Car
public int Id get; set;
public string Name get; set;
public Car()
JObject jsonData = JObject.Parse(File.ReadAllText(Environment.CurrentDirectory+ @"local.settings.json"));
Id = Convert.ToInt32(jsonData.Root.SelectToken("Car")["Id"]);
Name = Convert.ToString(jsonData.Root.SelectToken("Car")["Name"]);
The run method in Function.cs:
[FunctionName("Function1")]
public static void Run([TimerTrigger("0 */1 * * * *")]TimerInfo myTimer, ILogger log)
log.LogInformation($"C# Timer trigger function executed at: DateTime.Now");
Car c = new Car();
log.LogInformation($"the id is: c.Id");
log.LogInformation($"the name is: c.Name");
The test result:

You can follow the code below, and please point me out if I misunderstand you.
My local.settings.json file:
"IsEncrypted": false,
"Values":
"AzureWebJobsStorage": "xxxxx",
"FUNCTIONS_WORKER_RUNTIME": "dotnet"
,
"Car":
"Id": "123",
"Name": "name_1"
The Car.cs:
public class Car
public int Id get; set;
public string Name get; set;
public Car()
JObject jsonData = JObject.Parse(File.ReadAllText(Environment.CurrentDirectory+ @"local.settings.json"));
Id = Convert.ToInt32(jsonData.Root.SelectToken("Car")["Id"]);
Name = Convert.ToString(jsonData.Root.SelectToken("Car")["Name"]);
The run method in Function.cs:
[FunctionName("Function1")]
public static void Run([TimerTrigger("0 */1 * * * *")]TimerInfo myTimer, ILogger log)
log.LogInformation($"C# Timer trigger function executed at: DateTime.Now");
Car c = new Car();
log.LogInformation($"the id is: c.Id");
log.LogInformation($"the name is: c.Name");
The test result:

answered Mar 8 at 6:07
Ivan YangIvan Yang
3,829128
3,829128
Please see my update
– Pingpong
Mar 8 at 15:30
add a comment |
Please see my update
– Pingpong
Mar 8 at 15:30
Please see my update
– Pingpong
Mar 8 at 15:30
Please see my update
– Pingpong
Mar 8 at 15:30
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55053325%2fstore-and-load-function-app-settings-as-json-object-with-c-sharp-and-azure-funct%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown