Skip to main content
Question

Combining key value pair to an array

  • June 14, 2019
  • 4 replies
  • 48 views

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.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"
            }
        }

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"
   ]
 }
}
This post is closed to further activity.
It may be an old question, an answered question, an implemented idea, or a notification-only post.
Please check post dates before relying on any information in a question or answer.
For follow-up or related questions, please post a new question or idea.
If there is a genuine update to be made, please contact us and request that the post is reopened.

4 replies

redgeographics
Celebrity
Forum|alt.badge.img+62

You could try the JSONTemplater to get the desired result


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

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+13

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

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?