I'm using exiftool as Windows command line application. This exiftool variant delivers JSON output to stdout, a user can see it or forward it to a file via the command line > sign. But this has caused serious problems when calling exiftool from a Powershell script.
The exiftool documentation claims that the encoding of this output is strict UTF-8 (and I assume this is right) but apparently Powershell is able to transform this to a strange UTF-16 encoding. In particular: the German ß is used in Straße = street, quite common for photo metadata. The UTF-8 encoding of ß is C3 9F as two single bytes and this becomes in this UTF-16 C3-00 and 78-01 as two 16-bit integers. But these two double-byte character codes cannot be transformed back to C3 9F with simple means like the NET System.Text.Encoding, a home grown code transformation at byte level is required - that's tricky and error prone.
Therefore it would be a great feature of exiftool if JSON could be exported as file using UTF-8 encoding.
This is a "feature" of powershell and isn't something that exiftool can fix. See this thread (https://exiftool.org/forum/index.php?topic=8137.0) for a couple links documenting the behavior.
Well, if exiftool writes directly into a file then the forwarding or piping of the output is not required and we could forget about this strange Powershell behaviour.
Use the -w option to write directly to a file.
- Phil
Oh yes, -w works with JSON data. Thanks for the hint :)
When reading the help about -json I was concluding that exporting JSON data in the sense of writing them to a file is not supported. I compared the -json help with the -csv help which instantly talks about exporting metadata - while -json only talks about console output.
Right. The -w option sends the console output to a file for all output formats except -csv (which is unique).
Maybe you missed this near the very start of the documentation?:
Metadata is read from source files and printed in readable form to the
console (or written to output text files with -w).
- Phil
Phil, it's not easy to keep track of many particles of content in more than 2000 lines of the help file. But I know that it is hard to write an easy to read documentation from my job at IPTC.
Hello
You can also ask PowerShell to generate output files in UTF-8
ex:
ls | out-file ls-utf8.txt -encoding utf8
Best regards