api StructFormat JSON help

Started by sebutzu, July 16, 2023, 06:01:28 PM

Previous topic - Next topic

sebutzu

I am trying to use the new api StructFormat JSON:
exiftool.exe -all -j -struct -t -s -l -G:0:1 -api StructFormat=JSON -v3 -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"}]} "C:\Work\test photos\s.jpg"
I get a lot of errors:
At line:1 char:132
+ ... t=JSON -v3 -XMP:XMP-mwg-rs:RegionInfo={"AppliedToDimensions":{"H":508 ...
+                                                                 ~
Unexpected token ':' in expression or statement.
At line:1 char:137
+ ... v3 -XMP:XMP-mwg-rs:RegionInfo={"AppliedToDimensions":{"H":508,"Unit": ...
+                                                              ~~~~
Unexpected token ':508' in expression or statement.
At line:1 char:141
+ ... 3 -XMP:XMP-mwg-rs:RegionInfo={"AppliedToDimensions":{"H":508,"Unit":" ...
+                                                                 ~

What am I doing wrong?
Can you give me an example on how to use it correctly?
I would also like to use JSON format to be able to set the value of fields that are not structs, like IPTC:IPTC:Keywords. Would that be possible? Like -Keywords=["K1","K2"] (because this is the way their value is returned by -j option) ?

...trying more...
It seems like if I run this in the old command prompt (not PS) I get a different result:

Writing XMP-mwg-rs:RegionInfo
Invalid structure field at 'AppliedToDimensions:{H:508,...'
Warning: Invalid structure field at 'AppliedToDimensions:{H:508,...'
Ignored superfluous tag name or invalid option: -all
======== C:/Work/test photos/s.jpg
Rewriting C:/Work/test photos/s.jpg...
  Editing tags in: APP1 XMP
  Creating tags in: APP1 XMP
JPEG APP0 (14 bytes)
JPEG APP1 (126 bytes)
JPEG APP1 (1319 bytes)
  Rewriting XMP
    - XMP-mwg-rs:Regions/mwg-rs:AppliedToDimensions/stDim:h = '508'
    - XMP-mwg-rs:Regions/mwg-rs:AppliedToDimensions/stDim:unit = 'pixel'
    - XMP-mwg-rs:Regions/mwg-rs:AppliedToDimensions/stDim:w = '900'
    - XMP-mwg-rs:Regions/mwg-rs:RegionList/rdf:Bag/rdf:li 10/mwg-rs:Area/stArea:h = '0.639764'
    - XMP-mwg-rs:Regions/mwg-rs:RegionList/rdf:Bag/rdf:li 10/mwg-rs:Area/stArea:unit = 'normalized'
    - XMP-mwg-rs:Regions/mwg-rs:RegionList/rdf:Bag/rdf:li 10/mwg-rs:Area/stArea:w = '0.3'
    - XMP-mwg-rs:Regions/mwg-rs:RegionList/rdf:Bag/rdf:li 10/mwg-rs:Area/stArea:x = '0.261111'
    - XMP-mwg-rs:Regions/mwg-rs:RegionList/rdf:Bag/rdf:li 10/mwg-rs:Area/stArea:y = '0.457677'
    - XMP-mwg-rs:Regions/mwg-rs:RegionList/rdf:Bag/rdf:li 10/mwg-rs:Name = 'Stan'
    - XMP-mwg-rs:Regions/mwg-rs:RegionList/rdf:Bag/rdf:li 10/mwg-rs:Type = 'Face'
    - XMP-mwg-rs:Regions/mwg-rs:RegionList/rdf:Bag/rdf:li 11/mwg-rs:Area/stArea:h = '0.614173'
    - XMP-mwg-rs:Regions/mwg-rs:RegionList/rdf:Bag/rdf:li 11/mwg-rs:Area/stArea:unit = 'normalized'
    - XMP-mwg-rs:Regions/mwg-rs:RegionList/rdf:Bag/rdf:li 11/mwg-rs:Area/stArea:w = '0.295556'
    - XMP-mwg-rs:Regions/mwg-rs:RegionList/rdf:Bag/rdf:li 11/mwg-rs:Area/stArea:x = '0.615556'
    - XMP-mwg-rs:Regions/mwg-rs:RegionList/rdf:Bag/rdf:li 11/mwg-rs:Area/stArea:y = '0.307087'
    - XMP-mwg-rs:Regions/mwg-rs:RegionList/rdf:Bag/rdf:li 11/mwg-rs:Name = 'Oliver'
    - XMP-mwg-rs:Regions/mwg-rs:RegionList/rdf:Bag/rdf:li 11/mwg-rs:Type = 'Face'
    + XMP-mwg-rs:Regions/mwg-rs:~dummy~ = ''
JPEG APP13 (60 bytes)
JPEG DQT (65 bytes)
JPEG DQT (65 bytes)
JPEG SOF0:
JPEG DHT (29 bytes)
JPEG DHT (179 bytes)
JPEG DHT (29 bytes)
JPEG DHT (179 bytes)
JPEG SOS

Not sure still why some error messages here...And also it destroyed the tag in the file...

StarGeek

#1
The problem is with the quoting.  CMD is intercepting the quotes and reading them as part of the command.  So the internal quotes need to be escaped and it's probably a good idea to put the whole json string in quotes

C:\>exiftool -P -overwrite_original -api StructFormat=JSON -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\"}]}" y:\!temp\Test4.jpg
    1 image files updated

C:\>exiftool -G1 -a -s -xmp:all y:\!temp\Test4.jpg
[XMP-x]        XMPToolkit                      : Image::ExifTool 12.64
[XMP-mwg-rs]    RegionAppliedToDimensionsH      : 508
[XMP-mwg-rs]    RegionAppliedToDimensionsUnit  : pixel
[XMP-mwg-rs]    RegionAppliedToDimensionsW      : 900
[XMP-mwg-rs]    RegionAreaH                    : 0.639764, 0.614173
[XMP-mwg-rs]    RegionAreaUnit                  : normalized, normalized
[XMP-mwg-rs]    RegionAreaW                    : 0.3, 0.295556
[XMP-mwg-rs]    RegionAreaX                    : 0.261111, 0.615556
[XMP-mwg-rs]    RegionAreaY                    : 0.457677, 0.307087
[XMP-mwg-rs]    RegionName                      : Stan, Oliver
[XMP-mwg-rs]    RegionType                      : Face, Face

Edit: Re-reading, I'm assuming you're using PowerShell for the first attempt?  For that, all I can offer is to pay attention to the highlighting that PS displays.  Powershell works very poorly with exiftool commands, as it's quoting rules are different than any other shell.

For example, in this post, the image shows first how you would quote an exiftool command for CMD and then how you would quote it for Mac/Linux. The only difference between the two is the quotes are swapped.  But neither version works for PS.
"It didn't work" isn't helpful. What was the exact command used and the output.
Read FAQ #3 and use that cmd
Please use the Code button for exiftool output

Please include your OS/Exiftool version/filetype

sebutzu

What about:

QuoteI would also like to use JSON format to be able to set the value of fields that are not structs, like IPTC:IPTC:Keywords. Would that be possible? Like -Keywords=["K1","K2"] (because this is the way their value is returned by -j option) ?

StarGeek

Phil would have to confirm, but it does not appear to be possible in my quick test.
"It didn't work" isn't helpful. What was the exact command used and the output.
Read FAQ #3 and use that cmd
Please use the Code button for exiftool output

Please include your OS/Exiftool version/filetype

Phil Harvey

Values returned by the -j option may be used directly when writing with -j=, but the syntax is different from a "normal" assignment on the command line.  On the command line, I don't know how one would differentiate between the string '["K1","K1"]' and a JSON array.  Is it only the list-type tags that are the problem?

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