aspnet / Tooling

Issue tracker and info on Visual Studio tooling for ASP.NET
Other
258 stars 124 forks source link

Support for multi-line string values #1057

Closed shirhatti closed 6 years ago

shirhatti commented 6 years ago

From @alexvy86 on August 3, 2017 21:11

I'm using Akka.NET in a project and the way they do configuration is not-quite-JSON, but still a hierarchical structure, which I haven't been able to successfully integrate into appsettings.json. The only way I've been able to do it is to collapse all of their hierarchy into a single-line string value, which makes it a bit of a pain to work with.

For now I just put the whole thing as CDATA in an XML file and use the AddXmlFile() extension from Microsoft.Extensions.Configuration.Xml to read it, but it'd be preferable to have it in appsetings.json.

Copied from original issue: aspnet/Configuration#703

shirhatti commented 6 years ago

Can you share an example of what you're trying to achieve?

shirhatti commented 6 years ago

From @alexvy86 on August 15, 2017 22:9

Sure, see below. The value of AkkaConfig is a multi-line string which contains HOCON (JSON-like but not identical). Even though I didn't close the quotes that delimit the string value of AkkaConfig, VS thinks each new line is a different property in the JSON hierarchy and complains about the syntax (screenshot further down). If I don't close the string, I'd expect VS to interpret the value as a multi-line string, not try to parse the other lines as more JSON properties.

It also might be worth noting that in my application I want to retrieve the value as a string, not bound to a POCO by the configuration builder (which I wouldn't be able to do anyway, because HOCON and JSON are different enough).

{
  "AkkaConfig": "akka {
          loglevel = INFO
          log-config-on-start = off
          actor {
              debug {
                    receive = on
              }
          }
        }",
}

image

dgioulakis commented 6 years ago

😆 I stumbled here for the exact same reason (Akka's HOCON config). Was looking for a more elegant solution to add it to appSettings.json and thought multiline strings would be nice.

jimmylewis commented 6 years ago

The JSON grammar does not allow for multi-line strings1. The VS behavior is driven from this, since it would not be possible syntactically for the next line to be part of the string token.

1: See https://www.json.org/ especially the part defining string tokens where it excludes control characters.