ExifTool Forum

ExifTool => Bug Reports / Feature Requests => Topic started by: mws on January 16, 2018, 04:43:21 PM

Title: JSON output written to a file
Post by: mws on January 16, 2018, 04:43:21 PM
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.
Title: Re: JSON output written to a file
Post by: StarGeek on January 16, 2018, 06:20:34 PM
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.
Title: Re: JSON output written to a file
Post by: mws on January 17, 2018, 02:18:29 AM
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.
Title: Re: JSON output written to a file
Post by: Phil Harvey on January 17, 2018, 07:50:56 AM
Use the -w option to write directly to a file.

- Phil
Title: Re: JSON output written to a file
Post by: mws on January 22, 2018, 03:52:55 PM
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.
Title: Re: JSON output written to a file
Post by: Phil Harvey on January 22, 2018, 03:55:15 PM
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
Title: Re: JSON output written to a file
Post by: mws on January 30, 2018, 04:51:21 AM
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.
Title: Re: JSON output written to a file
Post by: digitalway on April 14, 2023, 03:05:33 AM
Hello
You can also ask PowerShell to generate output files in UTF-8

ex:
ls | out-file ls-utf8.txt -encoding utf8

Best regards