osm-search / Nominatim

Open Source search based on OpenStreetMap data
https://nominatim.org
GNU General Public License v3.0
2.98k stars 701 forks source link

geocodejson format can contain duplicate admin level keys #3382

Closed mtmail closed 3 months ago

mtmail commented 3 months ago

https://nominatim.openstreetmap.org/reverse?accept-language=en&addressdetails=1&format=geocodejson&lat=41.00488&lon=28.98016

returns level4 twice

  "label": "Agora Guesthouse, 10, Amiral Tafdil Sokağı, Cankurtaran Mahallesi, Istanbul, Fatih, Istanbul, Marmara Region, 34122, Turkey",
  "admin": {
    "level8": "Cankurtaran Mahallesi",
    "level4": "Istanbul",
    "level6": "Fatih",
    "level4": "Istanbul",
    "level3": "Marmara Region"
  }

It's not obvious because tools like JSON browser plugin, jq or some parsers ignore the second occurance silently. In fact duplicate keys seem to be allowed https://stackoverflow.com/questions/21832701/does-json-syntax-allow-duplicate-keys-in-an-object . The parser I'm using fails when it encounters a duplicate key.

I'll provide a PR for the output formatting but I wonder if the issue is deeper or if it's possible the values for the same level could also be different.

lonvia commented 3 months ago

Place nodes with admin_level again. They tend to be set for capitals and then refer to admin level of the administration they are the capital for. The geocodejson formatter should ignore everything that isn't a boundary=administrative.