JSON Output - type safety (for developers)

Started by sebutzu, January 05, 2025, 04:46:46 AM

Previous topic - Next topic

sebutzu

For developers it would be great if for each tag the export in json would produce a predictable type. Right now there are unexpected types (for example X,Y,H,W from RegionInfo Area are returned either as strings or as numbers in JSON).
It would be very helpful for each tag to have a type in JSON (maybe with listx or a new listj to be able to know those types), and to ensure that the produced JSNO actually has that type always.
This would also be helpful for lists to always return arrays in JSON even if it is one element only, etc.
Otherwise it is a lot of work for each tag to try to parse it to all possible types and to try to convert the result into something useful for an application.

Phil Harvey

You can set -api structformat=jsonq to output all values as strings in the -json output.  You can also use the -sep option to flatten most arrays.

In general, it is not possible for ExifTool to know if a value is supposed to be a string or a number when reading (especially unknown information) from a text-based metadata format.

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