JSON output written to a file

Started by mws, January 16, 2018, 04:43:21 PM

Previous topic - Next topic

mws

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.

StarGeek

This is a "feature" of powershell and isn't something that exiftool can fix.  See this thread for a couple links documenting the behavior.
"It didn't work" isn't helpful. What was the exact command used and the output.
Read FAQ #3 and use that cmd
Please use the Code button for exiftool output

Please include your OS/Exiftool version/filetype

mws

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.

Phil Harvey

Use the -w option to write directly to a file.

- Phil
...where DIR is the name of a directory/folder containing the images.  On Mac/Linux/PowerShell, use single quotes (') instead of double quotes (") around arguments containing a dollar sign ($).

mws

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.

Phil Harvey

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
...where DIR is the name of a directory/folder containing the images.  On Mac/Linux/PowerShell, use single quotes (') instead of double quotes (") around arguments containing a dollar sign ($).

mws

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.

digitalway

Hello
You can also ask PowerShell to generate output files in UTF-8

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

Best regards