2

I want to parse the JSON response coming from HTTP REST call using the HTTPClient adapter in apama. The response string is as below,

{
    "geometry": {
                "type": "MultiPolygon",
                "cordinates": [
                                [   
                                    [
                                        [
                                            -2.420261362208627,
                                            51.29662513520916
                                        ],
                                        [
                                            -2.42211658046158,
                                            51.28747916639892
                                        ],
                                        [
                                            -2.439047101373828,
                                            51.28519049850415
                                        ],
                                        [
                                            -2.453288677334455,
                                            51.273848703615954
                                        ]
                                    ]
                                ]   
                            ]
            },          
      "properties": {
                "name": "Bath and NE Somerset",
                "public_name": "Bath and North East Somerset",
                "region": "South West",
                "public_region": "South West"
            }
}

I wrote an event definition for the same as below,

event E {


 dictionary<string,dictionary<dictionary<string,string>,dictionary<string,sequence<sequence<sequence<sequence<float > > > > > > > geometry;

dictionary<string,string> properties;
    }

But during runtime it was giving error : Expecting map but getting a list.

Please help.

  • Unlike `properties`, you can't apply the data type `dictionary` to `Geometry` as the data types of value fields are not consistent when you compare keys `type` and `coordinates` inside `geometry`. They are of types `string` and `dictionary` instead. `Event` type allows you to define different types within itself for different elements, what `dictionary` type just can't. :) – Saurav Sahu May 16 '19 at 04:16

1 Answers1

2

You're treating geometry as a dictionary of string keys and dictionary values. This isn't true, as the first entry is a string:string pair. You'd be better suited declaring an event type, like so:

event Geometry {
    string type;
    sequence<sequence<sequence<sequence<float> > > > coordinates;
}

event E {
    Geometry geometry;
    dictionary<string,string> properties;
}