Invoke-RestMethod/Invoke-WebRequest should set charset=utf-8 for application/json by default
See original GitHub issueRecently had an issue trying to use a GitHub API when I put emojis in the POST body:
$body = ConvertFrom-Json @{
tag_name = "tag"
name = "demo"
body = "I like 🐛s"
draft = $true
prerelease = $true
}
$uri = "https://api.github.com/repos/me/bughunter/releases"
$headers = @{
GitHubToken = $myToken
Accept = "application/vnd.github.v3+json"
}
Invoke-RestMethod -Method Post -Uri $uri -Body $body -Headers $headers
Sending this published a draft with the description:
I like ??s
Took me a while to work out I needed -ContentType "application/json; charset=utf-8"
, which is fine. Except everything else defaulted (as expected) to UTF-8, so I assumed this would too.
Issue Analytics
- State:
- Created 4 years ago
- Reactions:2
- Comments:6 (2 by maintainers)
Top Results From Across the Web
Spring set default Content-type to "application/json;charset ...
The simplest solution for default content type charset, that I found, ... GET, produces = { "application/json; charset=utf-8" }) public ...
Read more >application/json character set with entity(as[String]) is not ...
Shouldn't the default charset for "application/json" be UTF-8 also when decoding the entity? I recall there was a similar issue with JSON ...
Read more >Benefit to specifying JSON Content-Type character set?
According to the RFC for the application/json Media Type: JSON text SHALL be encoded in Unicode. The default encoding is UTF-8. Since the...
Read more >Use JSON content-type for key-values - Azure App ...
Data is stored in App Configuration as key-values, where values are treated as the string type by default. However, you can specify a...
Read more >How to customize character encoding with System.Text.Json
By default, the encoder is initialized with the BasicLatin range. To serialize all language sets without escaping, use UnicodeRanges.All.
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Given that our console and output encoding default to utf-8, it seems like the webcmdlets should also follow with utf-8 as default charset unless overridden. cc @markekraus
That’s a UTF8 BOM encoded as ASCII or other non- Saw it take down a production service a few jobs ago when an xml feed encoded in UTF-8 decided to also send the optional BOM.

U+FEFF Byte Order Mark