Author Topic: Add support for -H and -D to JSON  (Read 2958 times)

dcampbell

  • Newbie
  • *
  • Posts: 4
Add support for -H and -D to JSON
« on: April 01, 2013, 10:37:25 AM »
Hi,

I would like the JSON output (-j) to support the -D and -H flags. I have attached a patch for exiftool version 9.24.

Phil Harvey

  • ExifTool Author
  • Administrator
  • ExifTool Freak
  • *****
  • Posts: 13339
    • ExifTool Home Page
Re: Add support for -H and -D to JSON
« Reply #1 on: April 01, 2013, 11:28:15 AM »
Thanks for this patch, it looks useful.

What about also printing non-numeric tag ID's as is done with XML (-X -H) ?

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

Phil Harvey

  • ExifTool Author
  • Administrator
  • ExifTool Freak
  • *****
  • Posts: 13339
    • ExifTool Home Page
Re: Add support for -H and -D to JSON
« Reply #2 on: April 01, 2013, 12:37:30 PM »
I have added the functionality of this patch, but I had to make some changes because the -php option uses the same code.  It now also prints non-numerical tag ID's.  The patch from the original exiftool is:

Code: [Select]
                 $noDups{$tok} = 1;
                 print $fp ',' if $comma;
                 print $fp qq(\n$ind"$tok"$sep );
+                if ($showTagID) {
+                    my $id = $exifTool->GetTagID($tag);
+                    $id = sprintf('0x%.4x', $id) if $showTagID eq 'H' and $id =~ /^\d+$/;
+                    $val = { id => $id, val => $val };
+                }
                 FormatJSON($fp, $val, $ind);
                 $comma = 1;
                 next;

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

dcampbell

  • Newbie
  • *
  • Posts: 4
Re: Add support for -H and -D to JSON
« Reply #3 on: April 01, 2013, 03:43:57 PM »
Thanks, this essentially looks good, but -j -H will now print decimal values for some tags, for example MPImage{Flags,Format,Type}, which have fractional decimal values for tag ID's. It would make more sense if their tag ID's were 0 as they are with the text output and -H flag, or if they were strings.

Phil Harvey

  • ExifTool Author
  • Administrator
  • ExifTool Freak
  • *****
  • Posts: 13339
    • ExifTool Home Page
Re: Add support for -H and -D to JSON
« Reply #4 on: April 01, 2013, 07:18:45 PM »
I did it this way because that is how it is done for the -X output.  The plain text output is different just to keep the columns lined up nicely.  But thinking about this more, the decimal values should technically be strings (for both -D and -H) because "12.1" is different than "12.10".  But quoting these would be a royal pain because then I couldn't use my FormatJSON() routine. :(

I'm not sure if the gain is worth the pain.  Does it impact you personally?

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

dcampbell

  • Newbie
  • *
  • Posts: 4
Re: Add support for -H and -D to JSON
« Reply #5 on: April 02, 2013, 11:04:35 AM »
I am migrating some code that was using the plain text output to json so that newline characters will not be lost, so the decimal/string issue may affect us, but even without strings we have more information about the tags than we did before and the decimal values are not hard to check for. So, while I like the idea of -H not returning decimal values and not equal tag IDs not being equal, I don't have a real world example of something it breaks.

Phil Harvey

  • ExifTool Author
  • Administrator
  • ExifTool Freak
  • *****
  • Posts: 13339
    • ExifTool Home Page
Re: Add support for -H and -D to JSON
« Reply #6 on: April 02, 2013, 11:37:37 AM »
OK.  It isn't pretty, but with a simple hack to FormatJSON() I can string-ify all decimal ID's (for both -D and -H).  I'll go ahead with this unless you have a better suggestion.

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

dcampbell

  • Newbie
  • *
  • Posts: 4
Re: Add support for -H and -D to JSON
« Reply #7 on: April 02, 2013, 02:06:34 PM »
I don't have a better idea, and I don't know enough about ID's and exiftool to know whether turning all of the decimal values into strings could be harmful.

Phil Harvey

  • ExifTool Author
  • Administrator
  • ExifTool Freak
  • *****
  • Posts: 13339
    • ExifTool Home Page
Re: Add support for -H and -D to JSON
« Reply #8 on: April 02, 2013, 02:20:51 PM »
Actually, I think I may have been wrong about "12.1" being different from "12.10".  (I was thinking about tag values, where this does occur.  For ID's this doesn't happen).  So they should probably be numbers with -D, and strings with -H.  Darn.  More complications.

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