How to remove special chars in JSON file format
Sometimes you want to write out an object in JSON format to a file. This is fine and what you would normally use ConvertTo-Json for.
The only issue is the generated JSON will convert some chars like <
to \u003c
which is not ideal for your JSON output. This seems to be a limitation with the PowerShell command.
To fix this, use this Regex snippet below to replace the escaped tokens in your output to make the file more readable.
This will turn your output from:
to
Note: you still will need to escape some chars like "
and \
but these are more managable.
Last updated