Forum Discussion
Passing Arguments to Notebooks with Magic
- 1 year ago
That still gave the same error, but I figured it out.
Unexpected character encountered while parsing value: i. Path 'isDev', line 1, position 10.
The variables set in the parent notebook already get passed to this child notebook, so passing the parameter wasn't even needed and what worked was simply:
Notebook1
isDev = True
%run Notebook2
Notebook2
print(str(isDev))
Also the following worked if I wanted to run it like a script, but the using the magic command was better and 10x faster.
Notebook1
params = {"isDev":True}mssparkutils.notebook.run("Notebook2", 120, params)Notebook2
print(str(isDev))
Thanks!
Hi PANDAmonium
Thank you for reaching out microsoft fabric community forum.
Convert the dictionary into a JSON string using json.dumps() before passing it to %run.
Notebook1
isDev = True
%run Notebook2 {json.dumps({'isDev': isDev})}
Notebook2
print(str(isDev)) # This should now work correctly
- json.dumps({'isDev': isDev}) converts the dictionary into a valid JSON string.
- %run Notebook2 {json.dumps({'isDev': isDev})} correctly passes the argument in a format that the %run magic command can parse.
This might help you to resolve the JsonReaderException error and allow isDev to be correctly passed to Notebook2.
If you need further assistance please feel free to reach us.
If this solution helps, please consider giving us Kudos and accepting it as the solution so that it may assist other members in the community
Thank you.
That still gave the same error, but I figured it out.
Unexpected character encountered while parsing value: i. Path 'isDev', line 1, position 10.
The variables set in the parent notebook already get passed to this child notebook, so passing the parameter wasn't even needed and what worked was simply:
Notebook1
isDev = True
%run Notebook2
Notebook2
print(str(isDev))
Also the following worked if I wanted to run it like a script, but the using the magic command was better and 10x faster.
Notebook1
Notebook2
print(str(isDev))
Thanks!