Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to escape a comma in json passed as args in a VSCode launcher.json command?

I would like to debug an APP and need to pass a in-line json as arg. I did the following:

    "configurations": [
        {
            "name": "app DEV",
            "program": "lib/main.dart",
            "request": "launch",
            "type": "dart",
            "args": [
                "--dart-define=APP_BACKENDS={[{\"id\":\"default\",\"url\":\"https://localhost\",\"port\": \"8080\"},]}",
            ]
        }

but the APP_BACKENDS const value is getting stripped in the first comma. lock the print of it: {[{"id":"default"


just to be clear. that is the way I'm getting the value I've printed:

static const _APP_BACKENDS =
      String.fromEnvironment('APP_BACKENDS', defaultValue: '{}');
like image 609
Cristiano Avatar asked Oct 22 '25 22:10

Cristiano


1 Answers

After going through a lot of links and reading, finally I found a GitHub issue https://github.com/microsoft/vscode/issues/98471 which solved my similar problem. If you go through the link and read the second last comment it explains the things regarding shell quoting.

"configurations": [
    {
        "name": "app DEV",
        "program": "lib/main.dart",
        "request": "launch",
        "type": "dart",
        "args": [
            "--dart-define=APP_BACKENDS={[{\"id\":\"default\",\"url\":\"https://localhost\",\"port\": \"8080\"},]}",
        ],
        "argsExpansion": "none"
    }

"argsExpansion": "none" after adding this to my launch.json file I was able to run the code without adding extra \ or spaces as mentioned in other answers. I tried searching for this configuration in vscode docs but did not find any reference, however it worked for me.

like image 154
Indrajit Avatar answered Oct 25 '25 14:10

Indrajit