web
You’re offline. This is a read only version of the page.
close
Skip to main content

Announcements

News and Announcements icon
Community site session details

Community site session details

Session Id :
Power Platform Community / Forums / Power Automate / PAD - JSON fails when ...
Power Automate
Answered

PAD - JSON fails when calling Python3 from Powershell

(0) ShareShare
ReportReport
Posted on by 13

Working on a new flow that will manipulate submitted audio files then submits the merged file to our phone system.

The Powershell and Python script work flawlessly together when launched from Visual Studio Code and Powershell ISE, on both my computer and the virtual environment it'll be living on. When PAD initiates the Powershell script then I get JSON errors in Python.

The JSON file created by Powershell has been the same exact thing whether if it's from PAD, Visual Studio, or ISE.
I've tried different ways of creating JSON and even passing JSON straight from Powershell to Python, but I get the same error. 

 

I understand that PAD uses IronPython, which I did install but ran into issues with installing needed resources. Since I already have other projects utilizing Python3 I'd prefer to stick with it.

 

Mostly confused why it works just fine when I run in from VSC and ISE but it PAD touches it then Python has issues with JSON. I'm still learning so there are probably a few things I can do better with these scripts.

Error:

 

Traceback (most recent call last):
File "C:\*****\MP3-WAV.py", line 8, in <module>
py=json.load(ps1)
^^^^^^^^^^^^^^
File "C:\*****\Python\Python311\Lib\json\__init__.py", line 293, in load
return loads(fp.read(),
^^^^^^^^^^^^^^^^
File "C:\*****\Python\Python311\Lib\json\__init__.py", line 346, in loads
return _default_decoder.decode(s)
^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\*****\Python\Python311\Lib\json\decoder.py", line 337, in decode
obj, end = self.raw_decode(s, idx=_w(s, 0).end())
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\*****\Python\Python311\Lib\json\decoder.py", line 355, in raw_decode
raise JSONDecodeError("Expecting value", s, err.value) from None
json.decoder.JSONDecodeError: Expecting value: line 1 column 1 (char 0)

 

 

Power Automate Desktop:

zlothra_0-1668556155379.png

 

Powershell Script:

 

param($Aud1,$Aud2,$Aud3,$cmpgnName,$scrptPath)
 $Aud1="%Audio1%"
 $Aud2="%Audio2%"
 $Aud3="%Audio3%"
 $cmpgnName="%campaignName%"
 $scrptPath='C:\*****\'

#Create JSON
 $JSON=[pscustomobject]@{
 Aud1=$Aud1
 Aud2=$Aud2
 Aud3=$Aud3
 cmpgnName=$cmpgnName
 }
 $JSON | ConvertTo-Json -Depth 4 | Out-File "C:\*****\ps1Py.json"
 $JSON | ConvertTo-Json -Compress | Write-Output

Set-Location -Path $scrptPath
 python MP3-WAV.py

 

 

JSON:

 

{
 "Aud1": "1test.mp3",
 "Aud2": "2test.wav",
 "Aud3": "3test.mp3",
 "cmpgnName": "testFinal"
}

 

 

Python Script:

 

from pydub import AudioSegment
import ffmpeg, json, os

jsonPS1 = 'C:\\*****\\ps1Py.json'
with open(jsonPS1, 'r') as ps1:
 py=json.load(ps1)

ls=[py['Aud1'],py['Aud2'],py['Aud3']]
cmpgnName=(py['cmpgnName'])
count=0

for index in range(len(ls)):
 count=count+1
 if ls[index] != '' and ls[index].endswith('.mp3'):
 file=ls[index].replace(ls[index], f"Audio{index+1}.wav")
 aud=AudioSegment.from_mp3(f"C:\\*****\\{ls[index]}")
 aud=aud.set_channels(1)
 aud.export(f"C:\\*****\\{file}", format='wav')
 os.remove(f"C:\\*****\\{ls[index]}")
 elif ls[index] != '' and ls[index].endswith('.wav'):
 file=ls[index].replace(ls[index], f"Audio{index+1}.wav")
 aud=AudioSegment.from_wav(f"C:\\*****\\{ls[index]}")
 aud=aud.set_channels(1)
 aud.export(f"C:\\*****\\{file}", format='wav')
 os.remove(f"C:\\*****\\{ls[index]}")

aud1=AudioSegment.from_wav("C:\\*****\\Audio1.wav")
aud2=AudioSegment.from_wav("C:\\*****\\Audio2.wav")
aud3=AudioSegment.from_wav("C:\\*****\\Audio3.wav")

if count == 3:
 outfile=aud1+aud2+aud3
 outfile.export(f"C:\\*****\\{cmpgnName}.wav", format="wav")
elif count == 2:
 outfile=aud1+aud2
 outfile.export(f"C:\\*****\\{cmpgnName}.wav", format="wav")
else:
 outfile=aud1
 outfile.export(f"C:\\*****\\{cmpgnName}.wav", format="wav")

 

  • Verified answer
    zlothra Profile Picture
    13 on at

    Found the issue, PAD is using Powershell 5 and for some reason it didn't like what I was doing. So I updated the script to switch to Powershell 7 and now it's working just fine.

     

    Source: automation - Can I change powershell version to 7 with "Run PowerShell script" action on Power Automate Desktop? - Stack Overflow

     

    $psVersion=(Get-Host).Version.Major
     IF($psVersion -ne 7){
     $processInfo=New-Object System.Diagnostics.ProcessStartInfo
     $processInfo.FileName="C:\Program Files\PowerShell\7\pwsh.exe"
     $processInfo.RedirectStandardError=$true
     $processInfo.RedirectStandardOutput=$true
     $processInfo.UseShellExecute=$false
     $processInfo.Arguments=$MyInvocation.MyCommand.Definition
     $process=New-Object System.Diagnostics.Process
     $process.StartInfo=$processInfo
     $process.Start() | Out-Null
     $process.WaitForExit()
     }else{
     param($Aud1,$Aud2,$Aud3,$cmpgnName,$scrptPath)
     $Aud1="%Audio1%"
     $Aud2="%Audio2%"
     $Aud3="%Audio3%"
     $cmpgnName="%campaignName%"
     $scrptPath='C:\*****\'
    
     $JSON=[pscustomobject]@{
     Aud1=$Aud1
     Aud2=$Aud2
     Aud3=$Aud3
     cmpgnName=$cmpgnName
     }
     $JSON | ConvertTo-Json -Depth 4 | Out-File "C:\*****\ps1Py.json"
     Set-Location -Path $scrptPath
     python MP3-WAV.py
    }

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Season of Sharing Community Challenge Winners!

Congratulations to our community stars!

Kudos to our 2025 Community Spotlight Honorees

Expanding mentorship, skilling, and AI innovation

Leaderboard > Power Automate

#1
11manish Profile Picture

11manish 307 Super User 2026 Season 2

#2
Mohsin Ali Profile Picture

Mohsin Ali 289

#3
Henil Profile Picture

Henil 127

Last 30 days Overall leaderboard