ExifTool Forum

ExifTool => Developers => Topic started by: sebutzu on January 04, 2025, 06:44:34 PM

Title: MWG RegionInfo returned in JSON format is wrong...
Post by: sebutzu on January 04, 2025, 06:44:34 PM
When I get values in JSON for MWG RegionInfo I get all kinds of strange things:
"RegionList": [{
      "Area": {
        "H": "0.08813364058732986",
        "Unit": "normalized",
        "W": "0.05125432461500168",
        "X": 0.598075270652771,
        "Y": 0.3986175060272217
      },

or
"Area": {
        "H": "0.06826037168502808",
        "Unit": "normalized",
        "W": "0.04368511959910393",
        "X": 0.3118512034416199,
        "Y": "0.43706798553466797"
      },

For some reason, some of the values (not all, not the same always) come inside quotes, others not.
I would assume since the tags for X, Y, W, H are defined as real, I would always get them as numbers in JSON, not sometimes as numbers sometimes as strings.
It is quite impossible to work with this in an application, without having any type guarantees on what the JSON contains.
Is there something I can do? It would be nice if this things would behave in a predictable way, if I ever hope to parse this kind of JSON data in an application.
Thanks a lot for any help or suggestions.
Title: Re: MWG RegionInfo returned in JSON format is wrong...
Post by: StarGeek on January 05, 2025, 09:31:46 AM
If exiftool thinks the value is a number, then it will be returned without quotes. Though I don't know why exiftool isn't doing so in this case.

You can add the -api StructFormat option (https://exiftool.org/ExifTool.html#StructFormat) with -api StructFormat=JSONQ which will force quotes around numbers.

Phil would have to comment further on this.

edit: One thing I should point out is that number of decimal places far exceeds what is needed. You would probably need an image millions (billions?) of pixels in size for the 15th decimal place to ever affect the region.

The old Google Picasa program would ignore any regions that had more than 9 decimal places. I currently use Photool's Imatch which reduces it to 6 decimal places, which would still be accurate on an image up to 500,000x500,000 pixels (half a pixel with each ±0.000001 change).
Title: Re: MWG RegionInfo returned in JSON format is wrong...
Post by: Phil Harvey on January 05, 2025, 05:29:21 PM
I seem to recall that some JSON parsers had a limit on the number of significant digits in a floating point value, so more than this and it is passed as a string.

- Phil