JSON Response Parsing in Apama HTTPClient adapter

106 views Asked by At

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.

1

There are 1 answers

0
Antony Marsden On

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;
}