I have a shortcode to count some cities in the world base on a json file as follows:
<ul>
{{ range .Site.Data.places }}
{{ $p := . }}
<li>{{ $p.properties.name }} (<strong>{{ $p.properties.country }}</strong>) </li>
{{ end }}
</ul>
{{ $json := getJSON "data/places.json" }}
<strong>{{- len $json -}}</strong> cities in <strong> ?? countries </strong>
The json file is as follows :
[
{
"type": "Feature",
"properties": {
"name": "New York City",
"country": "USA",
"description": null
},
"geometry": {
"type": "Point",
"coordinates": [-74.0059728, 40.7127753]
}
},
{
"type": "Feature",
"properties": {
"name": "San Fransisco",
"country": "USA",
"description": null
},
"geometry": {
"type": "Point",
"coordinates": [-122.443, 37.7562]
}
},
{
"type": "Feature",
"properties": {
"name": "Mexico City",
"country": "Mexico",
"description": null
},
"geometry": {
"type": "Point",
"coordinates": [-99.1333, 19.4333]
}
}
]
I am able to count the number of cities (with len $json) but I have difficulties to count the associated countries (without duplication)
Thanks in advance for your help