appsettings.json ⇄ environment variables

Paste appsettings.json to get the environment variable names .NET reads (Logging__LogLevel__Default), ready for your platform. Or paste variables to get the JSON back.

Flattening checked against Microsoft.Extensions.Configuration.Json and .EnvironmentVariables 10.0: same keys, same values, including arrays, booleans, numbers, nulls and empty arrays. Comments and trailing commas are accepted, as the JSON provider accepts them.

Questions

Why double underscores instead of colons?

Microsoft’s configuration documentation: “In environment variables, a colon separator doesn’t work on all platforms. A double underscore (__) is supported by all platforms and is automatically converted into a colon (:) when the configuration is read by the app.”

How are arrays written?

The index is another part of the name: Cors:Origins:0 becomes Cors__Origins__0. Microsoft’s documentation: “the array index should be treated as an additional element name in the path.”

Why does true become True?

The JSON provider stores every value as a string, and it writes JSON booleans as True and False. Numbers keep their exact JSON text. This page copies what the provider does, checked against Microsoft.Extensions.Configuration.Json.

Do keys with a dot work, like Microsoft.AspNetCore?

The configuration system reads them, but bash can’t export a name containing a dot (bash names allow only letters, digits and underscores). The bash output marks those lines so you can set them another way, or rename the key.

What does the prefix do?

If you call AddEnvironmentVariables("MYAPP_"), only variables starting with MYAPP_ are read, with the prefix removed. Put the same prefix here.

More tools

Runs in your browser: nothing you paste is sent anywhere. Not affiliated with Microsoft, the .NET Foundation or the library authors.