# CommandLinker? Proper syntax for command arguments?

**URL:** <https://discourse.jupyter.org/t/commandlinker-proper-syntax-for-command-arguments/26610>\
**Category:** JupyterLab\
**Tags:** how-to, help-wanted\
**Created:** [June 28, 2024, 9:59pm UTC](https://discourse.jupyter.org/t/commandlinker-proper-syntax-for-command-arguments/26610 "2024-06-28T21:59:17Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![gutow](https://yyz1.discourse-cdn.com/flex031/user_avatar/discourse.jupyter.org/gutow/32/4721_2.png) [@gutow](https://discourse.jupyter.org/u/gutow)\
**Post date:** [June 28, 2024, 9:59pm UTC](https://discourse.jupyter.org/t/commandlinker-proper-syntax-for-command-arguments/26610/1 "2024-06-28T21:59:17Z")

</div>

I can use the CommandLinker ([How to drive jupyter lab from a notebook using a jupyter lab extension · Issue #5789 · jupyterlab/jupyterlab · GitHub](https://github.com/jupyterlab/jupyterlab/issues/5789#issuecomment-449175515) and [How to call three commands with one button?](https://discourse.jupyter.org/t/how-to-call-three-commands-with-one-button/19374)) to run commands from javascript+html in notebook cells. My problem is that I am seeing the following error when I try to pass arguments to the command:

```auto
Uncaught SyntaxError: JSON.parse: expected property name or '}' at line 1 column 2 of the JSON data
    _evtClick http://localhost:8889/static/lab/jlab_core.c1feae0690cd2229a88c.js?v=c1feae0690cd2229a88c:1
    handleEvent http://localhost:8889/static/lab/jlab_core.c1feae0690cd2229a88c.js?v=c1feae0690cd2229a88c:1
jlab_core.c1feae0690cd2229a88c.js:1:152248

```

Things I have tried:

```auto
data-commandlinker-args="{args:{tableID:\'it_1719608870053\'}}"

```

```auto
data-commandlinker-args="{tableID:\'it_1719608870053\'}"

```

```auto
data-commandlinker-args="{tableID:'it_1719608870053'}"

```

plus other variations on quotations around the arguments in the `-args` string. The last one seems to work with `JSON.stringify()`, but the error is the same for all of them. I am trying some workarounds for my use case (rewriting the offending command so that it does not need arguments), but would be happy to get the arguments working with the CommandLinker.

Any hints?

Thanks,  
Jonathan

---

<div class="post-metadata">

**Author:** ![gutow](https://yyz1.discourse-cdn.com/flex031/user_avatar/discourse.jupyter.org/gutow/32/4721_2.png) [@gutow](https://discourse.jupyter.org/u/gutow)\
**Post date:** [June 28, 2024, 10:17pm UTC](https://discourse.jupyter.org/t/commandlinker-proper-syntax-for-command-arguments/26610/2 "2024-06-28T22:17:23Z")

</div>

Additional related question. Is the issue that line 183 in commandlinker.ts is:

```auto
          args = JSON.parse(argsValue);

```

rather than:

```auto
          args = JSON.parse(JSON.stringify((argsValue));

```

?  
If so is there a way to include arguments in the form of valid JSON when the html format requires “” around the value?

Thanks,  
Jonathan

---

<div class="post-metadata">

**Author:** ![krassowski](https://yyz1.discourse-cdn.com/flex031/user_avatar/discourse.jupyter.org/krassowski/32/1685_2.png) [@krassowski](https://discourse.jupyter.org/u/krassowski)\
**Post date:** [July 1, 2024, 5:57am UTC](https://discourse.jupyter.org/t/commandlinker-proper-syntax-for-command-arguments/26610/3 "2024-07-01T05:57:38Z")

</div>

The arguments that you are passing are not a valid JSON. JSON is a very strict format, it requires double quotes for keys and string values and no trailing commas. The followign ones should work:

```html
data-commandlinker-args='{"tableID": "it_1719608870053"}'

```

```html
data-commandlinker-args="{\"tableID\": \"it_1719608870053\1"}"

```

It is `JSON.parse` because the value of `data-commandlinker-args` is a string already.

---

<div class="post-metadata">

**Author:** ![gutow](https://yyz1.discourse-cdn.com/flex031/user_avatar/discourse.jupyter.org/gutow/32/4721_2.png) [@gutow](https://discourse.jupyter.org/u/gutow)\
**Post date:** [July 1, 2024, 6:45pm UTC](https://discourse.jupyter.org/t/commandlinker-proper-syntax-for-command-arguments/26610/4 "2024-07-01T18:45:10Z")

</div>

Thank you. I was able to get your first example working with careful escaping for my use case. My specific use case is passing a javascript string wrapping what I want in the python `display(HTML(<html string>))` call to a code cell. The syntax that worked was:

```auto
stringtoinsert = 'display(HTML(\'<button 
data-commandlinker-command="LockLabels:jupyter-inputtable" 
data-commandlinker-args=\\\'{"tableID":"'+ID+'"}\\\'>
Button Text</button>\'))';

```

(Editted to fix missing `\`'s for escaping)

Your second example assuming `\1"` is actually `\"` does not work for me (at least in FireFox). However, counter-intuitively the following does (although I could not come up with an escape sequence allowing me to pass it from a javascript string):

```auto
data-commandlinker-args="{"tableID": "it_1719608870053"}"

```
