Author Topic: Batch import .JSON into corresponding .JPG file possible?  (Read 356 times)

umdaman

  • Newbie
  • *
  • Posts: 5
Batch import .JSON into corresponding .JPG file possible?
« 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.

Phil Harvey

  • ExifTool Author
  • Administrator
  • ExifTool Freak
  • *****
  • Posts: 14405
    • ExifTool Home Page
Re: Batch import .JSON into corresponding .JPG file possible?
« Reply #1 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
...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 ($).

umdaman

  • Newbie
  • *
  • Posts: 5
Re: Batch import .JSON into corresponding .JPG file possible?
« Reply #2 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.



Phil Harvey

  • ExifTool Author
  • Administrator
  • ExifTool Freak
  • *****
  • Posts: 14405
    • ExifTool Home Page
Re: Batch import .JSON into corresponding .JPG file possible?
« Reply #3 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
...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 ($).

umdaman

  • Newbie
  • *
  • Posts: 5
Re: Batch import .JSON into corresponding .JPG file possible?
« Reply #4 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.

Phil Harvey

  • ExifTool Author
  • Administrator
  • ExifTool Freak
  • *****
  • Posts: 14405
    • ExifTool Home Page
Re: Batch import .JSON into corresponding .JPG file possible?
« Reply #5 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
...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 ($).

umdaman

  • Newbie
  • *
  • Posts: 5
Re: Batch import .JSON into corresponding .JPG file possible?
« Reply #6 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!!
« Last Edit: December 20, 2018, 02:29:46 PM by umdaman »

Phil Harvey

  • ExifTool Author
  • Administrator
  • ExifTool Freak
  • *****
  • Posts: 14405
    • ExifTool Home Page
Re: Batch import .JSON into corresponding .JPG file possible?
« Reply #7 on: December 20, 2018, 09:28:15 PM »
I'll see about doing a release tomorrow if I have time.

- 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: 14405
    • ExifTool Home Page
Re: Batch import .JSON into corresponding .JPG file possible?
« Reply #8 on: December 21, 2018, 07:44:31 AM »
ExifTool 11.23 is now available.

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

umdaman

  • Newbie
  • *
  • Posts: 5
Re: Batch import .JSON into corresponding .JPG file possible?
« Reply #9 on: December 21, 2018, 07:58:04 AM »
AWESOME!!!   Worked perfect!   Thank you so much!

timwillems

  • Newbie
  • *
  • Posts: 2
Re: Batch import .JSON into corresponding .JPG file possible?
« Reply #10 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)

Phil Harvey

  • ExifTool Author
  • Administrator
  • ExifTool Freak
  • *****
  • Posts: 14405
    • ExifTool Home Page
Re: Batch import .JSON into corresponding .JPG file possible?
« Reply #11 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
...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 ($).

timwillems

  • Newbie
  • *
  • Posts: 2
Re: Batch import .JSON into corresponding .JPG file possible?
« Reply #12 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"?

StarGeek

  • Global Moderator
  • ExifTool Freak
  • *****
  • Posts: 2365
Re: Batch import .JSON into corresponding .JPG file possible?
« Reply #13 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.  For more details, see CreativeCommons.org.
Troubleshooting hints:
* When posting, include your OS, Exiftool version, and type of file you're processing (MP4, JPG, etc).
* Double all percent signs (%) in a Windows batch file.
* If your GPS coords are negative, make sure and set the GpsLatitudeRef and GpsLongitudeRef tags correctly.

Phil Harvey

  • ExifTool Author
  • Administrator
  • ExifTool Freak
  • *****
  • Posts: 14405
    • ExifTool Home Page
Re: Batch import .JSON into corresponding .JPG file possible?
« Reply #14 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
...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 ($).