happytal / substitute-variables

Azure DevOps task for substituting variables in plain JSON and YAML files
MIT License
1 stars 0 forks source link

JSON File not recognized as JSON File #9

Closed grischtian closed 2 years ago

grischtian commented 2 years ago

Hi

I'm wondering receiving this error when I try to use this extension. The file appsettings.json is a JSON File. Does it have to be in UNIX Format or what else could be the problem?

2021-12-01T12:12:25.4379293Z ##[section]Starting: Substitute variables 2021-12-01T12:12:25.4505667Z ============================================================================== 2021-12-01T12:12:25.4506038Z Task : Substitute Variables 2021-12-01T12:12:25.4506336Z Description : Apply variable substitution to JSON and YAML files. 2021-12-01T12:12:25.4506626Z Version : 1.1.0 2021-12-01T12:12:25.4506840Z Author : happytal 2021-12-01T12:12:25.4508454Z Help : https://github.com/happytal/substitute-variables 2021-12-01T12:12:25.4508840Z ============================================================================== 2021-12-01T12:12:25.7608599Z Substituting variables in C:\inetpub\BudgetToolAD\appsettings.json 2021-12-01T12:12:25.7689542Z ##[error]File C:\inetpub\BudgetToolAD\appsettings.json is neither JSON nor YAML 2021-12-01T12:12:25.7750050Z ##[section]Finishing: Substitute variables

Regards, Christian

appsettings.json.txt

fhervieux commented 2 years ago

Hi!

The issue here is that the file is not standard JSON because it contains comments. The task relies on the default Node.js JSON parser which cannot parse it.

I am not sure if commented JSON files are quite common, but it seems some editors allow them. For exemple for appsettings.json files which are good candidates of files being processed by this plugin. I added support of commented JSON files using https://github.com/vitaly-t/decomment. It means comments will be stripped from the resulting file but at least the variable substitution will work.

This feature is deployed in version 1.2.0. It should already by available on the Azure DevOps Marketplace.

grischtian commented 2 years ago

Thanks for the quick reply and update to fix this issue! Unfortunately something is missing. It seems that the Marketplace version 1.2.0 still contains version 1.1.0. When I run the task, the error message still shows version 1.1.0 for this extension and the error is the same. image

fhervieux commented 2 years ago

I forgot to update the task version when publishing. I guess this is why it kept the 1.1.0 version and you still have the error. I just published version 1.2.1, hopefully it will fix the issue.

grischtian commented 2 years ago

Fantastic! This update fixed the issue!! Many thanks