my config file
config.config
%Image::ExifTool::UserDefined = (
'Image::ExifTool::XMP::Main' => {
xmpJson => {
SubDirectory => {
TagTable => 'Image::ExifTool::UserDefined::xmpJson',
},
},
},
);
%Image::ExifTool::UserDefined::xmpJson = (
GROUPS => { 0 => 'XMP', 1 => 'XMP-xmpJson', 2 => 'Other' },
NAMESPACE => { 'xmpJson' => 'http://ns.adobe.com/xmp/1.0/' },
WRITABLE => 'string',
Json => {
Struct => {
DebugJson => { Writable => 'string' },
},
List => 'Seq',
},
);
my tag data
data.txt
[
{
DebugJson={"a":1,"b:":2}
},
{
DebugJson={"a":3,"b:":4}
}
]
My operating system is Windows, when I run
.\exiftool -config config.config "-Json<=data.txt" 1.mp4
command, he gives me error:
Warning: DebugJson is not a structure in XMP xmpJson for XMP -xmpJson:Json
Nothing to do.
If I change DebugJson to 1 and 2 respectively, the output XML data looks like this
<rdf:Description rdf:about=''
xmlns:xmpJson='http://ns.adobe.com/xmp/1.0/'>
<xmpJson:Json>
<rdf:Seq>
<rdf:li rdf:parseType='Resource'>
<xmpJson:DebugJson>1
</xmpJson:DebugJson>
</rdf:li>
<rdf:li rdf:parseType='Resource'>
<xmpJson:DebugJson>2
</xmpJson:DebugJson>
</rdf:li>
</rdf:Seq>
</xmpJson:Json>
</rdf:Description>
I want to add json string to xmp tag, how can this be done, thank you very much! My thinking is that curly braces and commas may affect exiftool's parsing data, how to avoid it, let exiftool not parse curly braces and commas, and treat DebugJson as a Json string.
Like This
<rdf:Description rdf:about=''
xmlns:xmpJson='http://ns.adobe.com/xmp/1.0/'>
<xmpJson:Json>
<rdf:Seq>
<rdf:li rdf:parseType='Resource'>
<xmpJson:DebugJson>{"a":1,"b:":2}
</xmpJson:DebugJson>
</rdf:li>
<rdf:li rdf:parseType='Resource'>
<xmpJson:DebugJson>{"a":3,"b:":4}
</xmpJson:DebugJson>
</rdf:li>
</rdf:Seq>
</xmpJson:Json>
</rdf:Description>
You have explained this problem well.
Some characters must be escaped when a structure is serialized. Read here (https://exiftool.org/struct.html#Serialize) for the serialization rules.
Specifically, your data.txt file should be:
[
{
DebugJson=|{"a":1|,"b:":2|}
},
{
DebugJson=|{"a":3|,"b:":4|}
}
]
- Phil
Quote from: Phil Harvey on February 23, 2023, 09:31:43 AMYou have explained this problem well.
Some characters must be escaped when a structure is serialized. Read here (https://exiftool.org/struct.html#Serialize) for the serialization rules.
Specifically, your data.txt file should be:
[
{
DebugJson=|{"a":1|,"b:":2|}
},
{
DebugJson=|{"a":3|,"b:":4|}
}
]
- Phil
thank you! ;)
I should have mentioned that this writes a newline and a bunch of spaces at the end of your DebugJson value, but this seems to be what you wanted. If you change your mind, add a "," to the end of that line (after the closing brace) to avoid the extra whitespace in the output.
- Phil