1

I'm trying to convert Powershell Variable from Json and I get question marks instead of Hebrew.

As far as i know there is no encoding parameter for ConvertFrom-Json, any ideas how can i pass the hebrew?

take a look at this word: מחילמ

PS D:\wa2> $BotUpdates


StatusCode        : 200
StatusDescription : OK
Content           : {"succes":true,"response":[{"key":{"remoteJid":"","fromMe":false,"id":"","participant":""},"message":{"conversation":"***מחילמ***"},...
RawContent        : HTTP/1.1 200 OK
                    Connection: keep-alive
                    Keep-Alive: timeout=5
                    Content-Length: 308
                    Content-Type: application/json; charset=utf-8
                    Date: Thu, 24 Dec 2020 13:35:35 GMT
                    ETag: W/"134-v3U3d/6PCvlXMASgH7...
Forms             : {}
Headers           : {[Connection, keep-alive], [Keep-Alive, timeout=5], [Content-Length, 308], [Content-Type, application/json; charset=utf-8]...}
Images            : {}
InputFields       : {}
Links             : {}
ParsedHtml        : mshtml.HTMLDocumentClass
RawContentLength  : 308

And after converting from Json

PS D:\wa2> ($BotUpdates | ConvertFrom-Json).response

key                                                                                                                      message                    messageTimestamp participant                
---                                                                                                                      -------                    ---------------- -----------                
@{remoteJid=18XXXXXX; fromMe=False; id=3AXXXXXX67A1; participant=9} @{conversation=??????????} 1608816932       



PS D:\wa2>

take a look at @{conversation=??????????}

Any ideas?

Moshiko
  • 29
  • 5
  • That is curious, given that the response object itself suggests that the response was received correctly - or are you not showing the raw output? `ConvertFrom-Json` operates on .NET strings already in memory, whereas interpretation of character encoding happens only when `Invoke-WebRequest` parses the request and constructs these .NET strings. The response suggests UTF-8 encoding, which `Invoke-WebRequest` should pick up on via the `Content-Type` header field. As an aside: For JSON APIs it is generally simpler to use `Invoke-RestMethod`, as it has `ConvertFrom-Json` built in, so to speak. – mklement0 Dec 24 '20 at 14:33
  • 1
    If you do find that the response's character encoding is misinterpreted, you can try to _re-encode_ afterwards, as shown in [this answer](https://stackoverflow.com/a/53034595/45375). – mklement0 Dec 24 '20 at 14:35
  • That's probably related to Console output encoding (`$OutputEncoding`) and original string is perfectly fine. You can redirect it to a file (with correct encoding) and verify. – Giorgi Chakhidze Dec 27 '20 at 16:38

1 Answers1

0

Well, I would like to update that I solved it by converting

($BotUpdates.content | ConvertFrom-Json).response

Instead of

($BotUpdates | ConvertFrom-Json).response
Moshiko
  • 29
  • 5