Here's a geojson
object, which has array of features, each feature has a properties
object.
I understand that there are many question related to map arrays and objects but I couldn't find a similar case. I tried to use lodash map
and groupBy
to map the properties and group the values under their key
but honestly I just don't know what the combination of functions should be.
I can get the property name part by doing the following:
// since properties are the same for all features
// I extract them alone first
let properties = Object.keys(features[0].properties)
properties.map(Prentelement =>
{
let formated = {
// this gives me the first part
propertyName: Prentelement,
// I can't figure out this part to map the values uniquely under
children: [
{
value: "alex"
},
{
value: "cairo"
}
]
}
return formated;
})
This is an example of the input format:
{
"type": "FeatureCollection",
"features": [
{
"type": "Feature",
"properties": {
"Name": "cairo",
"Type": "Province"
}
},
{
"type": "Feature",
"properties": {
"Name": "alex",
"Type": "Province"
}
}
]
}
And what I want to do is a kind of summary on each available property and their possible values across different features. Please note that a value can be repeated across features but I want it available only once in the end result. So result would be an array like this:
[
{
propertyName: "Name",
children: [
{value: "alex"},
{value: "cairo"}
]
},
{
propertyName: "Type",
children: [
{value: "Province"}
]
}
]