ExifTool Forum

ExifTool => The "exiftool" Application => Topic started by: umdaman on December 20, 2018, 11:50:57 AM

Title: Batch import .JSON into corresponding .JPG file possible?
Post by: umdaman on December 20, 2018, 11:50:57 AM
I have downloaded my collections from FlickR with some software that created .JSON files for each image.  I would like to batch process each directory to add the Description and Tags and Title to my .JPG files.

Example of files
100_2440.jpg
100_2440.jpg.json

100_2441.jpg
100_2441.jpg.json

Is there anyway to process the entire directory and match up the .JSON with correct .JPG ?

Also I manually did 1 file, and it only seems to import the Description and Title.
XMP Toolkit                     : Image::ExifTool 10.57
Description                     : This is a test description
Title                           : IMG_2543

Data in the tested .JSON file: 
{"Tags":"Test, Area, province","Description":"This is a test description","Title":"IMG_2543"}

I was thinking the idea having the Tags for the image would be so that when uploaded to FlickR, or maybe even Google photos, that it would automatically import TAGS for searching, and Description and title so that I would not have to enter that for each image uploaded.... 

Are TAGS not supported?


Hope someone can help me out here.
Title: Re: Batch import .JSON into corresponding .JPG file possible?
Post by: Phil Harvey on December 20, 2018, 11:54:37 AM
Try this:

exiftool -tagsfromfile %d%f.%e.json "-SOMETAG<tags" -description -title -ext jpg DIR

where SOMETAG is the name of the tag you want the "Tags" metadata to go.  The Description and Title will be written to the XMP tags with these names.  Maybe using XMP "Subject" for SOMETAG makes sense.

- Phil
Title: Re: Batch import .JSON into corresponding .JPG file possible?
Post by: umdaman on December 20, 2018, 12:25:02 PM
Thanks!   I'm getting a little closer.   I had to change -tagsfromfile to -json  .  When I had -tagsfromfile I got an error: Error: File format error - 100_2440.jpg.json. on all the files.

Warning: No writable tags set from 100_2440.jpg
Warning: No writable tags set from 100_2441.jpg
Warning: No writable tags set from IMG_2539.jpg
Warning: No writable tags set from IMG_2540.jpg
Warning: No writable tags set from IMG_2541.jpg
Warning: No writable tags set from IMG_2542.jpg
    1 directories scanned
    2 image files updated

So out of the 8 files in the directory, I'm not sure why 2 worked and 6 others did not.


Title: Re: Batch import .JSON into corresponding .JPG file possible?
Post by: Phil Harvey on December 20, 2018, 12:40:42 PM
The -json option won't work.  It is meant to import a single json database for all files.

Can you attach one of your json files so I can try it out here?

- Phil
Title: Re: Batch import .JSON into corresponding .JPG file possible?
Post by: umdaman on December 20, 2018, 12:53:53 PM
Ok on the not using .json option.  now really weird I was just editing the json that worked to add different text to see if it was adding correct one when I did the .json option, now all 8 files unchanged.....

I have attached a couple files.
Title: Re: Batch import .JSON into corresponding .JPG file possible?
Post by: Phil Harvey on December 20, 2018, 01:02:44 PM
The problem is that your JSON files begin with a leading UTF-8 byte order mark.  I will patch ExifTool to allow this, but until the next release (11.23) you can work around this problem if you can remove the BOM from the start of the files.

- Phil
Title: Re: Batch import .JSON into corresponding .JPG file possible?
Post by: umdaman on December 20, 2018, 02:09:56 PM
Ahhhhhhhhhh!   I was wondering how the heck you saw that, but I did a type filename.json and I see that BOM your talking about!!    So the program I used that created those did that for some reason.  I wonder why.  So yes I edited one of my json's and cut and pasted the text into a new file, and saved it.   Then did what you told me and that worked!   I noticed the filesize of the .json was slightly smaller too.

Yes that will be great if you can fix that for the next release.  How long do you think before the next release is out?  I have like 16,000 photos that I'm working on.  I wonder if I could somehow create a simple Visual basic program that would rewrite all those .json files.

In the meantime I'm going to search if there is some kind of batch BOM remover.

Thanks for figuring this out for me!!
Title: Re: Batch import .JSON into corresponding .JPG file possible?
Post by: Phil Harvey on December 20, 2018, 09:28:15 PM
I'll see about doing a release tomorrow if I have time.

- Phil
Title: Re: Batch import .JSON into corresponding .JPG file possible?
Post by: Phil Harvey on December 21, 2018, 07:44:31 AM
ExifTool 11.23 is now available.

- Phil
Title: Re: Batch import .JSON into corresponding .JPG file possible?
Post by: umdaman on December 21, 2018, 07:58:04 AM
AWESOME!!!   Worked perfect!   Thank you so much!
Title: Re: Batch import .JSON into corresponding .JPG file possible?
Post by: timwillems on April 24, 2019, 11:01:53 AM
What about Flickr making names like _dsc1677_13425411743_o.jpg and photo_13425411743.json where just the number is the same? (working on Mac if that makes a difference)
Title: Re: Batch import .JSON into corresponding .JPG file possible?
Post by: Phil Harvey on April 24, 2019, 11:07:30 AM
Try this:

exiftool -tagsfromfile %d/photo_%-11.2f.json ... -ext jpg DIR

This should work as long as the file names all have this format with an 11-digit number.

- Phil
Title: Re: Batch import .JSON into corresponding .JPG file possible?
Post by: timwillems on April 24, 2019, 11:39:18 AM
Wonderful! It's writing the exif data into the jpg
Should I be worried about this:
"Warning: [minor] XMP-cc:License written as a literal because value is not a valid URI"?
Title: Re: Batch import .JSON into corresponding .JPG file possible?
Post by: StarGeek on April 24, 2019, 12:57:11 PM
No, unless you feel the need to have the XMP-cc:License tag be absolutely accurate.  It's the Creative Commons license that applies to the image.  It's a very rare tag that I've never seen actually used.

For exiftool details on it, see Creative Commons Tags (https://exiftool.org/TagNames/XMP.html#cc).  For more details, see CreativeCommons.org (https://creativecommons.org/).
Title: Re: Batch import .JSON into corresponding .JPG file possible?
Post by: Phil Harvey on April 24, 2019, 01:00:41 PM
Just for interest, what is the output of this command for the file?:

exiftool -XMP-cc:License FILE

- Phil
Title: Re: Batch import .JSON into corresponding .JPG file possible?
Post by: mr.SVG on October 23, 2019, 10:53:05 AM
Hello everybody!
I came to you from Flickr Help forum with topic "Update metadata from JSON file to JPEG"
Unfortunately, Flicker has lost some of my metadata in my JPG files after download 'em. About 1/3 of 40,000 photos lost "date_taken" info.

As is the case of topicstarter, I have downloaded my collections from FlickR with some software that created .JSON files for each image.  I would like to batch process each directory to add only one Tag "date_taken" to my .JPG files.

I really lucky that I successfully updated one of my JPEG file. But it was one problem - I have to remove "license" info in JSON data before.

Structure of my Data requested files was:
photo_21541919504.json
21541919504_60e8af7cff_o.jpg

I ran: exiftool -TagsFromFile photo_21541919504.json "-DateTimeOriginal<date_taken" 21541919504_60e8af7cff_o.jpg
and it updated successfully!

So I got two questions to respected community:
1) Which command should I run for removing license info "All Rights Reserved" in JSON data for ALL files?
2) Which command should I run for updating all JPEG files in a batch mode for only one Tag "date_taken"?
Thanks in advance for your any advice!
Title: Re: Batch import .JSON into corresponding .JPG file possible?
Post by: Phil Harvey on October 23, 2019, 11:08:10 AM
I'm not sure I understand what you are asking, but ExifTool doesn't have the ability to edit JSON files.  You can export selected metadata to a JSON file with the -j option, but importing from a JSON file will import all of the metadata from the file.

- Phil
Title: Re: Batch import .JSON into corresponding .JPG file possible?
Post by: StarGeek on October 23, 2019, 11:36:49 AM
Quote from: mr.SVG on October 23, 2019, 10:53:05 AM
I ran: exiftool -TagsFromFile photo_21541919504.json "-DateTimeOriginal<date_taken" 21541919504_60e8af7cff_o.jpg
and it updated successfully!
...
2) Which command should I run for updating all JPEG files in a batch mode for only one Tag "date_taken"?

Your command is pretty much the command to run, but the problem is matching the jpg file to the json file due to the differences in the file names.  In this case, the first 11 characters in the file name is what is needed to create the json name, but you should verify that this is the case for all the other files.

Your basic command would be something like:
exiftool --ext json -TagsFromFile %dphoto_%11f.json "-DateTimeOriginal<date_taken" /path/to/target/directory

Add the -r (recurse) option (https://exiftool.org/exiftool_pod.html#r-.--recurse) to recurse into subdirectories.  The -ext (extension) option (https://exiftool.org/exiftool_pod.html#ext-EXT---ext-EXT--extension) with two hyphens is used to make sure that json files are not processed while scanning directories.
Title: Re: Batch import .JSON into corresponding .JPG file possible?
Post by: mr.SVG on October 23, 2019, 02:11:28 PM
Quote from: Phil Harvey on October 23, 2019, 11:08:10 AM
I'm not sure I understand what you are asking, but ExifTool doesn't have the ability to edit JSON files.  You can export selected metadata to a JSON file with the -j option, but importing from a JSON file will import all of the metadata from the file.

- Phil
When I'm trying to writing the exif data into the jpg, the message appears:
"Warning: [minor] XMP-cc:License written as a literal because value is not a valid URI"
and nothing happens with updating.
To avoid this, I have to open .JSON file and delete license info "All Rights Reserved", I fill "0" instead.
If I do this, my JPEG converting successfull. How to do it in batch mode?
Quote from: StarGeek on October 23, 2019, 11:36:49 AM
.... with two hyphens is used to make sure that json files are not processed while scanning directories.

Thank you! My English is not so good, but worst of all, I was not familiar with the command line before. But I will try as hard as I can. Thanks again.
Title: Re: Batch import .JSON into corresponding .JPG file possible?
Post by: Phil Harvey on October 23, 2019, 02:20:14 PM
This warning shouldn't affect the way anything else is written.  ExifTool is just warning you that the XMP-cc:License will be stored in a non-standard format since it isn't a valid URL.  Everything else should still be written OK.

- Phil
Title: Re: Batch import .JSON into corresponding .JPG file possible?
Post by: Phil Harvey on October 23, 2019, 02:37:24 PM
To illustrate, here is the relevant XMP that is produced, both with an ok URI, and one that is not ok:

> exiftool -o -.xmp -xmp-cc:license="ok" | grep cc:license
  <cc:license rdf:resource='ok'/>

> exiftool -o -.xmp -xmp-cc:license="not ok" | grep cc:license
Warning: [minor] XMP-cc:License written as a literal because value is not a valid URI -
  <cc:license>not ok</cc:license>


Notice how the valid URI is stored as an rdf:resource, but the invalid one isn't.  A valid URI may not contain spaces (among other things).

- Phil
Title: Re: Batch import .JSON into corresponding .JPG file possible?
Post by: mr.SVG on October 31, 2019, 09:13:07 AM
Finaly I've updated all my 40K jpg files from Flickr, thanks to all good people from here and Flickr forum!  :)
But one problem is still here - I can't update *.PNG files. Not once not in a batch mode. It doesn't work anymore:
C\user\user>exiftool -TagsFromFile 21541919504.json "-DateTimeOriginal<date_taken" 21541919504.png
How can I update all my *.png files from *.json files with the same name in batch ? I need to update only one parameter "Date_taken"
Title: Re: Batch import .JSON into corresponding .JPG file possible?
Post by: Phil Harvey on October 31, 2019, 10:20:32 AM
What you you mean by "doesn't work"?  Is this FAQ number 3 (https://exiftool.org/faq.html#Q3)?

Check to see what tags are available in the JSON file with this command:

exiftool -s 21541919504.json

- Phil