In a PowerShell script, I have some custom data structure that contains Xml in string properties.
When I convert my data structure, useless encoding make the result difficult to read and write (json file used by my script may be manually adapted to match customer requirements before use).
Ex:
"<" | ConvertTo-Json
Returns :
"\u003c"
As far as I know, the <
is perfectly valid within a json string.
- Why
Convertto-Json
encode these character ? - Is there a way to avoid it ?
As a comparison, this code:
[System.Reflection.Assembly]::LoadWithPartialName("Newtonsoft.Json")
[Newtonsoft.Json.JsonConvert]::SerializeObject("<")
outputs:
"<"
But this solution relies on a 3rd party library and requires to ship it with my script (which are intended to be distributed to various customer environments).