You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
When you use Convertto-Json cmdlet and have an url in one of the properties of your hashtable then the output will show that there took some url encoding place during the conversion.
Expected behavior
I don't want the url encoding to happen. Or at least I want to be able to configure this if needed.
$uri='https://www.stranger.nl/thisisstrange?date=2015-04-05&value=foo&this#&%*'$body=@{
'url'=$uri
}
$body|convertto-json
[Reflection.Assembly]::LoadFile("C:\Program Files\WindowsPowerShell\Modules\newtonsoft.json\1.0.1.2\libs\Newtonsoft.Json.dll") |out-null
[Newtonsoft.Json.JsonConvert]::SerializeObject($body)
When using the Newtonsoft json classthe output is being show as expected.
Output:
{
"url": "https://www.stranger.nl/thisisstrange?date=2015-04-05\u0026value=foo\u0026this#\u0026%*"
}
{"url":"https://www.stranger.nl/thisisstrange?date=2015-04-05&value=foo&this#&%*"}
I'm also using Powershell 5.1 and I'm still getting this problem. ConvertTo-Json creates an useable url.
Is your answer to this in my world very critical error really to use PSCore6?
I'm also using Powershell 5.1 and I'm still getting this problem. ConvertTo-Json creates an useable url.
Is your answer to this in my world very critical error really to use PSCore6? $json.Replace("\u0026", "&")
Activity
[-]Convertto-Json and url encoding[/-][+]ConvertTo-Json and URL encoding[/+]SteveL-MSFT commentedon May 16, 2017
This doesn't repro with PSCore6 since we are using Newtonsoft Json.net
epernst commentedon Sep 2, 2020
I'm also using Powershell 5.1 and I'm still getting this problem. ConvertTo-Json creates an useable url.
Is your answer to this in my world very critical error really to use PSCore6?
vexx32 commentedon Sep 2, 2020
Yes. PowerShell 5.1 is not being actively maintained. How would you expect to get new features/bugfixes without using a new version of the product?
There may be other PowerShell modules available from the PSGallery which use newer JSON libraries as well that you could utilize.
xander-petty commentedon Apr 12, 2021