Get JSON file metadata bug

Started by JerryChao, November 10, 2023, 11:44:56 AM

Previous topic - Next topic

JerryChao

I'm testing exiftool getting json metadata.
i found a bug.

here is my report:

I have two files in a folder , they have the same content with different extension .
they are : "metadata.txt" and "metadata.json".


i use the following command to generate a new metadata json file : "2311102321-1.json"

exiftool.exe -n -j --json:all -s -sort  .\metadata.* > ..\output\2311102321-1.json

there is a line in "2311102321-1.json ", it should belongs to metadatas of "metadata.json" ,
but actually it's the content of "metadata.json" , not the metadata of "metadata.json" .

  "ImageSize": "1267 845",

if i use the following command , with out "--json:all " , gentrate a metadata json file "2311102321-2.json"

exiftool.exe -n -j -s -sort  .\metadata.* > ..\output\2311102321-2.json

there are a lot lines in "2311102321-2.json" belong to the content of "metadata.json" not the metadata of  "metadata.json" .

i think that is a bug .

the following attaches are files i mentioned in the report.


StarGeek

Quote from: JerryChao on November 10, 2023, 11:44:56 AMif i use the following command , with out "--json:all " , gentrate a metadata json file "2311102321-2.json"

exiftool.exe -n -j -s -sort  .\metadata.* > ..\output\2311102321-2.json

there are a lot lines in "2311102321-2.json" belong to the content of "metadata.json" not the metadata of  "metadata.json" .

i think that is a bug .

This is FAQ #3.  Running that command, you will see this output
[{
  "SourceFile": "Y:/!temp/x/y/metadata.json",
  "ExifTool:ExifToolVersion": 12.67,
  "System:Directory": "Y:/!temp/x/y",
  "System:FileAccessDate": "2023:11:10 09:26:32-08:00",
  "System:FileCreateDate": "2023:11:10 09:18:27-08:00",
  "System:FileModifyDate": "2023:11:10 09:18:27-08:00",
  "System:FileName": "metadata.json",
  "System:FilePermissions": 100666,
  "System:FileSize": 811,
  "System:ZoneIdentifier": "Exists",
  "File:FileType": "JSON",
  "File:FileTypeExtension": "JSON",
  "File:MIMEType": "application/json",
  "JSON:BitsPerSample": 8,
  "JSON:ColorComponents": 3,
  "JSON:Directory": "..",
  "JSON:EncodingProcess": 0,
  "JSON:ExifToolVersion": 12.69,
  "JSON:FileAccessDate": "2023:11:10 23:37:29+08:00",
  "JSON:FileCreateDate": "2023:11:08 15:40:42+08:00",
  "JSON:FileModifyDate": "2023:11:08 15:40:43+08:00",
  "JSON:FileName": "5E37306303A23424BED067307A8_02A8A22A_3764E.jpeg",
  "JSON:FilePermissions": 100666,
  "JSON:FileSize": 226894,
  "JSON:FileType": "JPEG",
  "JSON:FileTypeExtension": "JPG",
  "JSON:ImageHeight": 845,
  "JSON:ImageSize": "1267 845",
  "JSON:ImageWidth": 1267,
  "JSON:JFIFVersion": "1 1",
  "JSON:MIMEType": "image/jpeg",
  "JSON:Megapixels": 1.070615,
  "JSON:ResolutionUnit": 1,
  "JSON:SourceFile": "../5E37306303A23424BED067307A8_02A8A22A_3764E.jpeg",
  "JSON:XResolution": 220,
  "JSON:YCbCrSubSampling": "2 2",
  "JSON:YResolution": 220,
  "JSON:ZoneIdentifier": "Exists"
}]

Notice that there are tags with duplicate names, but in different groups.  Without the -a (-duplicates) option, exiftool will only return one value of a tag with the same name. For example, FileAccessDate appears in the System group, which belongs to the metadata of the file itself, and in the JSON group, which is value of the FileAccessDate tag in the file.  Without telling exiftool you want to see duplicated data with the -a option, you are only going to see one of these tags.
* Did you read FAQ #3 and use the command listed there?
* Please use the Code button for exiftool code/output.
 
* Please include your OS, Exiftool version, and type of file you're processing (MP4, JPG, etc).

StarGeek

Quote from: JerryChao on November 10, 2023, 11:44:56 AMi use the following command to generate a new metadata json file : "2311102321-1.json"

exiftool.exe -n -j --json:all -s -sort  .\metadata.* > ..\output\2311102321-1.json

there is a line in "2311102321-1.json ", it should belongs to metadatas of "metadata.json" ,
but actually it's the content of "metadata.json" , not the metadata of "metadata.json" .

  "ImageSize": "1267 845",

This one is a bit more complex.  In the previous command, I added the -e (--composite) option because I thought the Composite group wasn't needed.  But for this one, it is.

Running your command
C:\>exiftool -G1 -a -s -n -j --json:all -s -sort Y:\!temp\x\y\metadata.json
Config file not found
[{
  "SourceFile": "Y:/!temp/x/y/metadata.json",
  "ExifTool:ExifToolVersion": 12.67,
  "System:Directory": "Y:/!temp/x/y",
  "System:FileAccessDate": "2023:11:10 09:32:59-08:00",
  "System:FileCreateDate": "2023:11:10 09:18:27-08:00",
  "System:FileModifyDate": "2023:11:10 09:18:27-08:00",
  "System:FileName": "metadata.json",
  "System:FilePermissions": 100666,
  "System:FileSize": 811,
  "System:ZoneIdentifier": "Exists",
  "File:FileType": "JSON",
  "File:FileTypeExtension": "JSON",
  "File:MIMEType": "application/json",
  "Composite:ImageSize": "1267 845",
  "Composite:Megapixels": 1.070615
}]

Here, you can see that ImageSize and Megapixels are part of the Composite group (see Composite tags page).  These tags are created by exiftool on the fly.  In the case of ImageSize, exiftool will create that by combining the ImageHeight and ImageWidth tags.  It does not matter that these tags are part of the JSON group, they still have the tag names that exiftool combines to create the Composite:ImageSize.  And suppressing the JSON output with --json:all does not block the creation of the Composite tags.  For that, you need the -e option.
* Did you read FAQ #3 and use the command listed there?
* Please use the Code button for exiftool code/output.
 
* Please include your OS, Exiftool version, and type of file you're processing (MP4, JPG, etc).

JerryChao

#3
Thank you for your replay , I use "-e" with "--json:all" parameter ,get the meatadata of a json file that i think it's right.

in my mind , json should be considered as a txt file ,
such as source code file ".c", ".php", ".py" , ".java" .etc ,
or  ".ini" , ".log" , ".md" .etc .
even the ".bat" file.

they all should be trated as txt file .

the file encoding is a more concerned filed.

best wishes ~ ^_^

Phil Harvey

Quote from: JerryChao on November 11, 2023, 01:25:53 PMin my mind , json should be considered as a txt file

XMP and XML files are also TXT, do you think these should be treated as TXT as well?  (So nothing but filesystem information would be extracted from, say, an XMP 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 ($).