The ultimate Fabric, Power BI, SQL, and AI community-led learning event. Save €200 with code FABCOMM.
Get registeredCompete to become Power BI Data Viz World Champion! First round ends August 18th. Get started.
Hi All,
I'm trying to figure out how to use magic commands to run another notebook with an argument that has a variable as the value. Hopefully the example below explains it better. The idea is to pass a pipeline parameter to the notebook, for example a True/False variable on whether it's being run on dev, and have that also apply to another notebook being ran using magic.
Notebook1
isDev = True
%run Notebook2 {'isDev': isDev}
Notebook2
print(str(isDev))
When I use a string instead of a variable as the argument value it works. Otherwise I get this error:
MagicUsageError: Cannot parse notebook parameters. More details please visit https://go.microsoft.com/fwlink/?linkid=2270136 --> JsonReaderException: Unexpected character encountered while parsing value: i. Path 'isDev', line 1, position 9.
Thanks!
Solved! Go to Solution.
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!
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
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!