How to set json struct tags

Started by sebutzu, May 29, 2023, 04:35:52 PM

Previous topic - Next topic

sebutzu

using -j -struct I can extract tag values as JSON (example: XMP:XMP-mwg-rs:RegionInfo). Trying to set the value from the JSON itself, using -j -struct does not work. Is there a way to use "standard" JSON to set the value of struct tag? Not having to use some conversion of the string to a language particular format but use the standard JSON for interoperability?

Phil Harvey

From the application documentation:

            If JSONFILE is specified, the file is imported and the tag
            definitions from the file are used to set tag values on a per-file
            basis.  The special "SourceFile" entry in each JSON object
            associates the information with a specific target file.  An object
            with a missing SourceFile or a SourceFile of "*" defines default
            tags for all target files which are combined with any tags
            specified for the specific SourceFile processed.  The imported
            JSON file must have the same format as the exported JSON files
            with the exception that options exporting JSON objects instead of
            simple values are not compatible with the import file format (ie.
            export with -D, -H, -l, or -T is not compatable, and use -G
            instead of -g).  Additionally, tag names in the input JSON file
            may be suffixed with a "#" to disable print conversion.


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

StarGeek

Quote from: sebutzu on May 29, 2023, 04:35:52 PMTrying to set the value from the JSON itself, using -j -struct does not work.

Maybe I'm misunderstanding something, but it works here. Save XMP-mwg-rs:all to a json file from Temp3.jpg.  Edit the json file to remove the "SourceFile" entry.  Write XMP-mwg-rs:all from the json file to Test4.jpg with the -struct optionHere's the differences on DiffChecker.com.  Only difference is the SourceFile entry.

C:\>exiftool -P -overwrite_original -j -struct -XMP-mwg-rs:all y:\!temp\Test3.jpg >temp.txt

C:\>echo "edits json to remove sourcefile"
"edits json to remove sourcefile"

C:\>type temp.txt
[{
  "RegionInfo": {
    "AppliedToDimensions": {
      "H": 598.000000,
      "Unit": "pixel",
      "W": 945.000000
    },
    "RegionList": [{
      "Area": {
        "H": 0.082148,
        "Unit": "normalized",
        "W": 0.052000,
        "X": 0.773000,
        "Y": 0.247235
      },
      "Name": "John Smith",
      "Type": "Face"
    }]
  }
}]

C:\>exiftool -P -overwrite_original -struct -j=temp.txt y:\!temp\Test4.jpg
    1 image files updated

C:\>exiftool -P -overwrite_original -j -struct -XMP-mwg-rs:all y:\!temp\Test4.jpg
[{
  "SourceFile": "y:/!temp/Test4.jpg",
  "RegionInfo": {
    "AppliedToDimensions": {
      "H": 598.000000,
      "Unit": "pixel",
      "W": 945.000000
    },
    "RegionList": [{
      "Area": {
        "H": 0.082148,
        "Unit": "normalized",
        "W": 0.052000,
        "X": 0.773000,
        "Y": 0.247235
      },
      "Name": "John Smith",
      "Type": "Face"
    }]
  }
}]
* 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).

sebutzu

#3
I am NOT using a JSON file. I am using exiftool with stay_open true and passing commands form a C# wrapper. My problem is that in those commands, if I want to set the value as a JSON (format not file), I cannot - it is not accepted. I need to transform it into something not standard. Is there a way to do it?

So basically how to set the value of XMP-mwg-rs via command line (after stay open) in a JSON format(standard), not in a Perl specific format? (not using an external JSON file)

something like this:

exiftool.exe -j -struct -XMP:XMP-mwg-rs:RegionInfo='{"AppliedToDimensions":{"H":508,"Unit":"pixel","W":900},"RegionList":[{"Area":{"H":0.639764,"Unit":"normalized","W":0.3,"X":0.261111,"Y":0.457677},"Name":"Stan","Type":"Face"},{"Area":{"H":0.614173,"Unit":"normalized","W":0.295556,"X":0.615556,"Y":0.307087},"Name":"Oliver","Type":"Face"}] }' a.jpg

StarGeek

Phil would have to verify, but I would say no.  There isn't an option to change the how exiftool reads the data in a direct assignment.  To keep the sturcture, you'll have to convert it to structured formatting.
* 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).

Phil Harvey

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