AnsweredAssumed Answered

JSON Formatting for esri_json or geo_json

Question asked by jamesfreddyc on Sep 15, 2015
Latest reply on Sep 17, 2015 by bixb0012

First...  May I please mention how awful it is working with JSON strings?  This is horrendous to have to wade through this string manipulation work.

 

Okay.  Can someone please step in here and provide a fresh set of eyes because mine are entirely crossed attempting to untangle this mess.  I suppose this has to do with the fact that the calling application is not necessarily "GIS" based and I am having to work with a non-GEO/ESRI JSON formatted string as an input then attempt to make sense out of it.

 

Anyway...

 

I need to take the input JSON and setup a FeatureCollection so that I can process individual polygons.

 

The input:

 

input ="""[
  {
    "rings" : 
    [
      [[-117,34],[-116,34],[-117,33],[-117,34]], [[-115,44],[-114,43],[-115,43],[-115,44]]
    ]
  },
  {
    "rings" : 
    [
      [[32,17],[31,17],[30,17],[30,16],[32,17]]
    ]
  }
]"""

 

I need it to read as such:

 

main_json_string = """{"type":"FeatureCollection","features":[
                      {"type":"Feature","geometry":{"type":"Polygon","coordinates":[
                                                                                    [[-117,34],[-116,34],[-117,33],[-117,34]]]
                                                   }
                      },
                      {"type":"Feature","geometry":{"type":"Polygon","coordinates":[
                                                                                    [[32,17],[31,17],[30,17],[30,16],[32,17]]]
                                                   }
                      }]}"""

 

I am unable to pick out from the squiglies how to get it correct.  I started with some replace methods and finding it difficult to get it all converted correctly.  Any help is appreciated.

Outcomes