Deleting tags via JSON

Started by karlgustavv, December 10, 2014, 05:34:01 AM

Previous topic - Next topic

karlgustavv

Hello Phil.

If you want to delete a tag you will do something like:

exiftool -location= test.jpg
or
exiftool -location="" test.jpg

But if you specify

[{
  "SourceFile": "test.jpg",
  "Location": ""
}]


within a JSON-File and apply this to test.jpg the tag "location" won't get deleted. Exiftool leaves test.jpg with an empty location tag.

If this is intended how will I be able to remove tags via JSON?

Regards,
Karl

Phil Harvey

Hi Karl,

From the -json option documentation, you are referred to the -csv option:

            Empty values are ignored when importing.  Also, FileName and
            Directory columns are ignored if they exist (ie. ExifTool will not
            attempt to write these tags with a CSV import).  To force a tag to
            be deleted, use the -f option and set the value to "-" in the CSV
            file (or to the MissingTagValue if this API option was used).
            Multiple databases may be imported in a single command.


- 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 ($).

karlgustavv

#2
Hello Phil,

thank you very much for your fast answer.

So I will replace all "" with "-".

Regards,
Karl

PS: "Empty values are ignored when importing." This might be true for csv imports but with JSON the tag will be set to an ampty value ("Location": "" deletes the original location and sets it to "").
PPS: Stupid question: Is there a way to use -f for deleting tags via "Location": "-" and to keep/set tags that actually have the value "-"?

Phil Harvey

Hi Karl,

Odd.  I will investigate this apparent inconsistency.

- 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 ($).

Phil Harvey

Yes.  This is how it was meant to be.  The difference is due to the difference in format between CSV and JSON.  For JSON, empty values are not ignored.  But I will think about this some more...  Perhaps setting MissingTagValue to an empty string could trigger the behaviour you desire.

- 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 ($).

Phil Harvey

OK.  Setting MissingTagValue to an empty string works, but this must be done via the API (you can do this with a config file) because you can't set something to an empty string via the command line.

Also, I'll see about improving the -json documentation of this.

- 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 ($).

karlgustavv

Hi Phil,

adding

%Image::ExifTool::UserDefined::Options = (
    MissingTagValue => '',
);


to a config file really does the job.

Thanks a lot.

Regards,
Karl