Recommanded practice how to include more sophisticated configuration JSON data in Azure Function...
I am using Azure Functions 2
I am going through Azure Function Local settings file documentation here:
https://docs.microsoft.com/en-us/azure/azure-functions/functions-run-local#local-settings-file
Per documentation, here is an example of local.settings.json file:
{
"IsEncrypted": false,
"Values": {
"FUNCTIONS_WORKER_RUNTIME": "<language worker>",
"AzureWebJobsStorage": "<connection-string>",
"AzureWebJobsDashboard": "<connection-string>",
"MyBindingConnection": "<binding-connection-string>"
},
"Host": {
"LocalHttpPort": 7071,
"CORS": "*"
},
"ConnectionStrings": {
"SQLConnectionString": "<sqlclient-connection-string>"
}
}
I understand that the items in “Values” will be available through environment variables like Environment.GetEnvironmentVariable
I need to include more sophisticated settings ( nested JSON data with arrays in them) in my Function’s settings.
What would be the best practice or recommended practice to do that?
azure azure-functions azure-functions-runtime azure-functions-core-tools
add a comment |
I am using Azure Functions 2
I am going through Azure Function Local settings file documentation here:
https://docs.microsoft.com/en-us/azure/azure-functions/functions-run-local#local-settings-file
Per documentation, here is an example of local.settings.json file:
{
"IsEncrypted": false,
"Values": {
"FUNCTIONS_WORKER_RUNTIME": "<language worker>",
"AzureWebJobsStorage": "<connection-string>",
"AzureWebJobsDashboard": "<connection-string>",
"MyBindingConnection": "<binding-connection-string>"
},
"Host": {
"LocalHttpPort": 7071,
"CORS": "*"
},
"ConnectionStrings": {
"SQLConnectionString": "<sqlclient-connection-string>"
}
}
I understand that the items in “Values” will be available through environment variables like Environment.GetEnvironmentVariable
I need to include more sophisticated settings ( nested JSON data with arrays in them) in my Function’s settings.
What would be the best practice or recommended practice to do that?
azure azure-functions azure-functions-runtime azure-functions-core-tools
add a comment |
I am using Azure Functions 2
I am going through Azure Function Local settings file documentation here:
https://docs.microsoft.com/en-us/azure/azure-functions/functions-run-local#local-settings-file
Per documentation, here is an example of local.settings.json file:
{
"IsEncrypted": false,
"Values": {
"FUNCTIONS_WORKER_RUNTIME": "<language worker>",
"AzureWebJobsStorage": "<connection-string>",
"AzureWebJobsDashboard": "<connection-string>",
"MyBindingConnection": "<binding-connection-string>"
},
"Host": {
"LocalHttpPort": 7071,
"CORS": "*"
},
"ConnectionStrings": {
"SQLConnectionString": "<sqlclient-connection-string>"
}
}
I understand that the items in “Values” will be available through environment variables like Environment.GetEnvironmentVariable
I need to include more sophisticated settings ( nested JSON data with arrays in them) in my Function’s settings.
What would be the best practice or recommended practice to do that?
azure azure-functions azure-functions-runtime azure-functions-core-tools
I am using Azure Functions 2
I am going through Azure Function Local settings file documentation here:
https://docs.microsoft.com/en-us/azure/azure-functions/functions-run-local#local-settings-file
Per documentation, here is an example of local.settings.json file:
{
"IsEncrypted": false,
"Values": {
"FUNCTIONS_WORKER_RUNTIME": "<language worker>",
"AzureWebJobsStorage": "<connection-string>",
"AzureWebJobsDashboard": "<connection-string>",
"MyBindingConnection": "<binding-connection-string>"
},
"Host": {
"LocalHttpPort": 7071,
"CORS": "*"
},
"ConnectionStrings": {
"SQLConnectionString": "<sqlclient-connection-string>"
}
}
I understand that the items in “Values” will be available through environment variables like Environment.GetEnvironmentVariable
I need to include more sophisticated settings ( nested JSON data with arrays in them) in my Function’s settings.
What would be the best practice or recommended practice to do that?
azure azure-functions azure-functions-runtime azure-functions-core-tools
azure azure-functions azure-functions-runtime azure-functions-core-tools
edited Nov 24 '18 at 3:49
Jerry Liu
11k11130
11k11130
asked Nov 23 '18 at 19:16
Allan XuAllan Xu
1,82611939
1,82611939
add a comment |
add a comment |
1 Answer
1
active
oldest
votes
Values
collection is expected to be a Dictionary<string, string>
, therefore we can't put nested JSON data with arrays inside. Try to create a new section for your Json data and read Json file as usual. We can't use Environment.GetEnvironmentVariable
because the custom settings are not imported into environment variables.
{
"Values": {},
"CustomSettings":{}
}
Add ExecutionContext context
to function method signature to locate settings file.
var reader = new StreamReader(context.FunctionAppDirectory+"/local.settings.json");
var myJson = reader.ReadToEnd();
For v2 function, we can use ConfigurationBuilder
.
var config = new ConfigurationBuilder()
.SetBasePath(context.FunctionAppDirectory)
.AddJsonFile("local.settings.json", optional: false, reloadOnChange: true)
.AddEnvironmentVariables()
.Build();
local.settings.json
is designed to provide local dev with an equivalent of Application settings in Azure portal, it's not published to Azure by default. To publish it, right click on project> Edit <functionappname>.csproj
and remove <CopyToPublishDirectory>Never</CopyToPublishDirectory>
.
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%2f53451937%2frecommanded-practice-how-to-include-more-sophisticated-configuration-json-data-i%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
Values
collection is expected to be a Dictionary<string, string>
, therefore we can't put nested JSON data with arrays inside. Try to create a new section for your Json data and read Json file as usual. We can't use Environment.GetEnvironmentVariable
because the custom settings are not imported into environment variables.
{
"Values": {},
"CustomSettings":{}
}
Add ExecutionContext context
to function method signature to locate settings file.
var reader = new StreamReader(context.FunctionAppDirectory+"/local.settings.json");
var myJson = reader.ReadToEnd();
For v2 function, we can use ConfigurationBuilder
.
var config = new ConfigurationBuilder()
.SetBasePath(context.FunctionAppDirectory)
.AddJsonFile("local.settings.json", optional: false, reloadOnChange: true)
.AddEnvironmentVariables()
.Build();
local.settings.json
is designed to provide local dev with an equivalent of Application settings in Azure portal, it's not published to Azure by default. To publish it, right click on project> Edit <functionappname>.csproj
and remove <CopyToPublishDirectory>Never</CopyToPublishDirectory>
.
add a comment |
Values
collection is expected to be a Dictionary<string, string>
, therefore we can't put nested JSON data with arrays inside. Try to create a new section for your Json data and read Json file as usual. We can't use Environment.GetEnvironmentVariable
because the custom settings are not imported into environment variables.
{
"Values": {},
"CustomSettings":{}
}
Add ExecutionContext context
to function method signature to locate settings file.
var reader = new StreamReader(context.FunctionAppDirectory+"/local.settings.json");
var myJson = reader.ReadToEnd();
For v2 function, we can use ConfigurationBuilder
.
var config = new ConfigurationBuilder()
.SetBasePath(context.FunctionAppDirectory)
.AddJsonFile("local.settings.json", optional: false, reloadOnChange: true)
.AddEnvironmentVariables()
.Build();
local.settings.json
is designed to provide local dev with an equivalent of Application settings in Azure portal, it's not published to Azure by default. To publish it, right click on project> Edit <functionappname>.csproj
and remove <CopyToPublishDirectory>Never</CopyToPublishDirectory>
.
add a comment |
Values
collection is expected to be a Dictionary<string, string>
, therefore we can't put nested JSON data with arrays inside. Try to create a new section for your Json data and read Json file as usual. We can't use Environment.GetEnvironmentVariable
because the custom settings are not imported into environment variables.
{
"Values": {},
"CustomSettings":{}
}
Add ExecutionContext context
to function method signature to locate settings file.
var reader = new StreamReader(context.FunctionAppDirectory+"/local.settings.json");
var myJson = reader.ReadToEnd();
For v2 function, we can use ConfigurationBuilder
.
var config = new ConfigurationBuilder()
.SetBasePath(context.FunctionAppDirectory)
.AddJsonFile("local.settings.json", optional: false, reloadOnChange: true)
.AddEnvironmentVariables()
.Build();
local.settings.json
is designed to provide local dev with an equivalent of Application settings in Azure portal, it's not published to Azure by default. To publish it, right click on project> Edit <functionappname>.csproj
and remove <CopyToPublishDirectory>Never</CopyToPublishDirectory>
.
Values
collection is expected to be a Dictionary<string, string>
, therefore we can't put nested JSON data with arrays inside. Try to create a new section for your Json data and read Json file as usual. We can't use Environment.GetEnvironmentVariable
because the custom settings are not imported into environment variables.
{
"Values": {},
"CustomSettings":{}
}
Add ExecutionContext context
to function method signature to locate settings file.
var reader = new StreamReader(context.FunctionAppDirectory+"/local.settings.json");
var myJson = reader.ReadToEnd();
For v2 function, we can use ConfigurationBuilder
.
var config = new ConfigurationBuilder()
.SetBasePath(context.FunctionAppDirectory)
.AddJsonFile("local.settings.json", optional: false, reloadOnChange: true)
.AddEnvironmentVariables()
.Build();
local.settings.json
is designed to provide local dev with an equivalent of Application settings in Azure portal, it's not published to Azure by default. To publish it, right click on project> Edit <functionappname>.csproj
and remove <CopyToPublishDirectory>Never</CopyToPublishDirectory>
.
edited Nov 24 '18 at 4:02
answered Nov 24 '18 at 3:48
Jerry LiuJerry Liu
11k11130
11k11130
add a comment |
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%2f53451937%2frecommanded-practice-how-to-include-more-sophisticated-configuration-json-data-i%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