ExifTool Forum

ExifTool => Developers => Topic started by: Mac2 on November 23, 2024, 01:30:15 PM

Title: api gelocation and JSON differs from XML and plain output
Post by: Mac2 on November 23, 2024, 01:30:15 PM
exiftool -a -api geolocation=51.479345,-0.290328,num=2
Returns a warning ("Search matched 2 cities", which should probably only be emitted when data is written to a file?) and returns two sets of data for two matching cities. The same result is emitted with XML output when using -X.

But for -JSON, only one set of data is emitted (same warning). This seems inconsistent.

I understand from the docs that when writing location data, only one city can win (city with the largest population).
But when just dumping the information to the console or a stream, maybe ExifTool could output all matches found when -JSON is used, too? It already emits an array, which makes this very easy to parse.
Title: Re: api gelocation and JSON differs from XML and plain output
Post by: StarGeek on November 23, 2024, 01:38:21 PM
I believe this is cause. From the docs on the -j (-json) option (https://exiftool.org/exiftool_pod.html#j-JSONFILE--json)
QuoteThe -a option is implied when -json is used, but entries with identical JSON names are suppressed in the output. (-G4 may be used to ensure that all tags have unique JSON names.)
Title: Re: api gelocation and JSON differs from XML and plain output
Post by: Mac2 on November 24, 2024, 08:25:41 AM
I see, thanks.

With -G4, the JSON array (!) returned has still one object, but this object now uses unique element names like

"Unknown:GeolocationCity"
"Copy1:GeolocationCity"
"Copy2:GeolocationCity"
"Copy3:GeolocationCity"

Would it somehow be possible to output one object per city object in the array?
This would avoid all the duplicate name issues and would make parsing easier.
Title: Re: api gelocation and JSON differs from XML and plain output
Post by: Phil Harvey on November 25, 2024, 08:21:52 AM
I would suggest using -g3:

> exiftool -a -api geolocation=51.479345,-0.290328,num=2 -j -g3
[{
  "SourceFile": " ",
  "Main": {
    "GeolocationWarning": "Search matched 2 cities",
    "GeolocationCity": "Kew",
    "GeolocationRegion": "England",
    "GeolocationSubregion": "Greater London",
    "GeolocationCountryCode": "GB",
    "GeolocationCountry": "United Kingdom",
    "GeolocationTimeZone": "Europe/London",
    "GeolocationFeatureCode": "PPL",
    "GeolocationFeatureType": "Populated Place",
    "GeolocationPopulation": 11000,
    "GeolocationPosition": "51.4816, -0.2874",
    "GeolocationDistance": "0.33 km",
    "GeolocationBearing": 54
  },
  "Doc1": {
    "GeolocationCity": "Brentford",
    "GeolocationRegion": "England",
    "GeolocationSubregion": "Greater London",
    "GeolocationCountryCode": "GB",
    "GeolocationCountry": "United Kingdom",
    "GeolocationTimeZone": "Europe/London",
    "GeolocationFeatureCode": "PPL",
    "GeolocationFeatureType": "Populated Place",
    "GeolocationPopulation": 11000,
    "GeolocationPosition": "51.4862, -0.3083",
    "GeolocationDistance": "1.45 km",
    "GeolocationBearing": 291
  }
}]

- Phil
Title: Re: api gelocation and JSON differs from XML and plain output
Post by: Mac2 on November 25, 2024, 12:02:53 PM
Ah, that's better :)  Where there is an ExifTool, there is a way.
Thanks!