Skip to main content
Question

Combining key value pair to an array


jugoslaviaa
Enthusiast
Forum|alt.badge.img+6

Hi all, 

I have a geojson file, where I would like to concatenate the some key value pair to one as array. I have tried ListConcatenator however it simple concatenate without creating array. You can see the below my attempt and desired result. Thanks in advance. 

Output of ListConcatenator

{
            "type" : "Feature",
            "geometry" : {
                "type" : "LineString",
                "coordinates" : [
                    [ 4.345800876650.8345288033 ],
                    [ 4.34633195450.8348774905 ],
                    [ 4.347442388550.8357197041 ]
                ]
            },
            "properties" : {
                "osm_id" : "",
                "osm_way_id" : "30010739",
                "_amenity{0}.amenity" : "hospital",
                "_amenity{1}.amenity" : "pharmacy",
                "_amenity{2}.amenity" : "drinking_water",
                "_amenity{3}.amenity" : "pub",
                "_concatenated" : "hospital,waste_basket,pharmacy,drinking_water,pub"
            }
        }

Desired output 

{
 "type": "Feature",
 "geometry": {
   "type": "LineString",
   "coordinates": [
     [
       4.3458008766,
       50.8345288033
     ],
     [
       4.346331954,
       50.8348774905
     ],
     [
       4.3474423885,
       50.8357197041
     ]
   ]
 },
 "properties": {
   "osm_id": "",
   "osm_way_id": "30010739",
   "_amenity{0}.amenity": "hospital",
   "_amenity{1}.amenity": "pharmacy",
   "_amenity{2}.amenity": "drinking_water",
   "_amenity{3}.amenity": "pub",
   "_concatenated": [
     "hospital",
     "waste_basket",
     "pharmacy",
     "drinking_water",
     "pub"
   ]
 }
}

4 replies

redgeographics
Celebrity
Forum|alt.badge.img+50

You could try the JSONTemplater to get the desired result


jugoslaviaa
Enthusiast
Forum|alt.badge.img+6
  • Author
  • Enthusiast
  • June 19, 2019
redgeographics wrote:

You could try the JSONTemplater to get the desired result

Can you give me some hints? Never used it before and tried once and the results i got like this:

"_array" : "{ \\"amenity\\" : [ \\"parking\\", \\"recycling\\" ] }"


laurawatsafe
Safer
Forum|alt.badge.img+11

Hi @jugoslaviaa, What writer are you using in your workspace for this? I ran a quick test using the GeoJSON writer directly. If I send the _amenity{} list attribute directly to the writer, it automatically creates an array in the output for me like this:


jugoslaviaa
Enthusiast
Forum|alt.badge.img+6
  • Author
  • Enthusiast
  • July 2, 2019
lauraatsafe wrote:

Hi @jugoslaviaa, What writer are you using in your workspace for this? I ran a quick test using the GeoJSON writer directly. If I send the _amenity{} list attribute directly to the writer, it automatically creates an array in the output for me like this:

I am using also geojson. But it does not get written _amenity{} at all if I do not expose the elements beforehand. Am I missing something?


Cookie policy

We use cookies to enhance and personalize your experience. If you accept you agree to our full cookie policy. Learn more about our cookies.

 
Cookie settings