How to write to JSON file using jq without changing binary file at Powershell?
Answer a question
I have a simple jq command & it works when I run it in Powershell at a local computer. The binary file does not change.
jq 'query.....' $srcJson > $destinationJson
When Jenkins run the command above (located in a Powershell file) at a separate Windows computer, the $destinationJson binary file has changed.
For example:

bad-swagger.json file is created in Jenkins.
swagger.json file is created in local PowerShell windows.
Both text files have the same content but the file size is different by twice & the giff diff reveals that the binary file is different.
How to write in-place or save the new jq output to a json file without changing its binary file using Powershell?
Thank you.
Answers
The difference in output you're seeing is likely due to the fact that the file output redirection operation (>) in Windows PowerShell defaults to UTF16LE (or in Windows-speak "Unicode") encoding.
Instead of using >, try piping the output from jq to a cmdlet that allows you to explicitly set the output encoding, like Out-File:
jq 'query...' $srcJson |Out-File $destinationJson -Encoding UTF8
更多推荐
所有评论(0)