PowerShell 7.3 - how to to Parse JSON from API Response with Special Characters
I'm wondering if anyone has experience with I just started working with I'm upgrading from an older version and I'm working with PowerShell 7.3 to call a REST API that returns a JSON response. The JSON response contains special characters such as `&`, `%`, and `#`. When I try to parse this JSON using `ConvertFrom-Json`, I get an behavior: `ConvertFrom-Json : Invalid character in JSON at line 1, position 15.` I've tried using `Invoke-RestMethod` to fetch the data, and it seems to work fine until I hit the parsing step. Here's the code I'm using: ```powershell $response = Invoke-RestMethod -Uri 'https://api.example.com/data' -Method Get $json = $response | ConvertFrom-Json ``` To troubleshoot, I added a line to see the raw response: ```powershell $responseRaw = $response | ConvertTo-Json Write-Output $responseRaw ``` The output looks correct, but still fails on parsing. I also verified that the API is supposed to return valid JSON. I've considered encoding issues, so I checked the response headers for `Content-Type`, and it correctly indicates `application/json`. I've attempted to escape special characters using `-replace`, but that only led to additional errors when I tried parsing. Can anyone advise on how to properly handle this scenario, or if there's a better approach to parse the JSON response when special characters are involved? I'm on Ubuntu 20.04 using the latest version of Powershell. What are your experiences with this? This is part of a larger mobile app I'm building. How would you solve this? I'm working with Powershell in a Docker container on CentOS. Thanks for any help you can provide!