New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support for multi-line string values #1057

Closed
shirhatti opened this Issue Sep 12, 2017 · 4 comments

Comments

Projects
None yet
3 participants
@shirhatti
Member

shirhatti commented Sep 12, 2017

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

This comment has been minimized.

Member

shirhatti commented Sep 12, 2017

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

@shirhatti

This comment has been minimized.

Member

shirhatti commented Sep 12, 2017

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

@Cephei

This comment has been minimized.

Cephei commented Jun 1, 2018

😆 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

This comment has been minimized.

jimmylewis commented Jun 12, 2018

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.

@jimmylewis jimmylewis closed this Jun 25, 2018

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment