Skip to content
This repository was archived by the owner on Nov 16, 2023. It is now read-only.

Mistaken appsettings.json as YAML file #38

Open
mba-jyskefinans-dk opened this issue Feb 7, 2022 · 3 comments
Open

Mistaken appsettings.json as YAML file #38

mba-jyskefinans-dk opened this issue Feb 7, 2022 · 3 comments
Labels
bug Something isn't working

Comments

@mba-jyskefinans-dk
Copy link

When substituting variables in appsettings.json is mistaken the file as a YAML file.

image

@mba-jyskefinans-dk
Copy link
Author

Input json

{
"Logging": {
"LogLevel": {
"Default": "Information",
"Microsoft.AspNetCore": "Warning",
"Microsoft": "Warning"
},
"ApplicationInsights": {
"LogLevel": {
"Default": "Information",
"Microsoft.AspNetCore": "Information",
"Microsoft": "Warning"
}
}
},
"ApplicationInsights": {
"InstrumentationKey": "xxxxxxxxxxxxx"
},
"Monthio": {
"BaseUrl": "https://xxxxxxx-xxx.com",
"CreateSessionEndpoint": "api/smart-check-sessions",
"FlowUrl": "https://xxxx.xxxxx.com",
"Security":
{
"IdentityUrl": "https://xxxx.xxxxx.com",
"ClientId": "xxxxx",
"GrantType": "xxxxxx",
"Scope": "xxx",
"RefreshToken": "xxxxxxxxxxxxxx",

},
"JF_Configuration": {
  "Loan": 000
}

},
"AllowedHosts": "*"
}

Output:
Logging:
LogLevel:
Default: Information
Microsoft.AspNetCore: Warning
Microsoft: Warning
ApplicationInsights:
LogLevel:
Default: Information
Microsoft.AspNetCore: Information
Microsoft: Warning
ApplicationInsights:
InstrumentationKey: xxxxxxxxxxxxxxxxxxxxxx
Monthio:
BaseUrl: 'https://xxxxx.xxxxx.com'
CreateSessionEndpoint: api/smart-check-sessions
FlowUrl: 'https://xxxx.xxxxxx.com'
Security:
IdentityUrl: 'https://xxxxx.xxxxx.com'
ClientId: xxxxxx
GrantType: xxxxx
Scope: xxxx
RefreshToken: xxxxxxxxx
JF_Configuration:
Loan: 387
AllowedHosts: '*'

@BALAGA-GAYATRI BALAGA-GAYATRI added bug Something isn't working and removed need-to-triage labels Mar 21, 2022
@BALAGA-GAYATRI
Copy link
Contributor

@mba-jyskefinans-dk We shall look into this and keep you posted.

@ykopstein
Copy link

@mba-jyskefinans-dk I had the same error and discovered a stray comma at the end of an object in my JSON. Removing the stray comma got variable substitution to work. You also have a stray comma in your sample input - at the end of the Security object after the RefreshToken value.

@BALAGA-GAYATRI this happens because YML is officially a superset of JSON. Anything which is valid JSON is also valid YML. On line 103 of variableSubstitution.ts the JSON parser rejects the invalid JSON with a stray comma. Then on line 117 of variableSubstitution.ts the JSON doc is successfully loaded by the YML parser because it's less strict about the rules of JSON parsing. The result is it treats the JSON file as a YML file and does the substitution as YML. This would be fine except the output translates it into "standard" YML format instead of JSON and you end up with a "converted" file... from JSON to YML.

One solution might be to explicitly use FAILSAFE_SCHEMA in the safeLoad call to exclude JSON as a valid schema.

See also http://adilapapaya.com/docs/js-yaml/#safeloadstringoptions

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants