api gelocation and JSON differs from XML and plain output

Started by Mac2, November 23, 2024, 01:30:15 PM

Previous topic - Next topic

Mac2

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.

StarGeek

I believe this is cause. From the docs on the -j (-json) option
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.)
"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

Mac2

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.

Phil Harvey

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

Mac2

Ah, that's better :)  Where there is an ExifTool, there is a way.
Thanks!