Select to view content in your preferred language

GeoEvent Server - parsing many cardinality for array of coordinates to create geometry

995
1
Jump to solution
08-06-2020 10:11 AM
GeoffreyWest
Occasional Contributor III

Hi - 

I am working with the JSON below.  I would like to use data.last_known_position.geometry.coordinates as my X and Y.  The goal is to send the JSON to a stream service.  I am using the connector poll and external website for JSON.  I have referenced this thread here Parse JSON location data from array , to no avail.  My logs indicate that the fields data.last_known_position.geometry.coordinates[0] and data.last_known_position.geometry.coordinates[1] do no exist which would construct the geometry.  When I select "Create a GeoEvent Definition" for my input, the definition that is created contains many cardinality for the coordinates array. How can I get the values from data.last_known_position.geometry.coordinates to create my geometry?

{
"paging": {
"limit": 100,
"total": 292453,
"next": "dGltZT0xNTAyNTc5MzE1Ljc4ODA4LGlkPTA4MGRkYTM2LWU1MTktNDExNC1iZGRmLTJiNGM2ODk3YWRhMw=="
},
"data": [
{
"id": "b2c2626d-ff0b-4892-8262-5acae60946a4",
"name": "JUPITER II",
"mmsi": 701000533,
"imo": 9123726,
"call_sign": "LW 9897",
"ship_type": "Fishing",
"class": "A",
"flag": "AR",
"length": 27,
"width": 7,
"ais_version": 0,
"created_at": "2017-08-11T19:35:18.200135+00:00",
"updated_at": "2018-07-02T18:04:11.279030+00:00",
"last_known_position": {
"timestamp": "2018-07-02T14:57:58+00:00",
"geometry": {
"type": "Point",
"coordinates": [
- 62.82619,
- 45.29533
]
},
"heading": 511,
"speed": 4.3,
"rot": - 128,
"accuracy": null,
"collection_type": "satellite",
"draught": null,
"maneuver": 0,
"course": 154.6
},
"most_recent_voyage": {
"eta": "2019-06-12T17:00:00+00:00",
"destination": "MAR DEL PLATA"
},
"predicted_position": {
"timestamp": "2018-07-02T17:51:06+00:00",
"geometry": {
"type": "Point",
"coordinates": [
- 62.7929417229,
- 44.9985799193
]
},
"speed": 6.2,
"course": 5.3,
"confidence_radius": 34.3429
},
"general_classification": "Fishing Industry",
"individual_classification": "Fishing Vessel",
"gross_tonnage": "148",
"lifeboats": null,
"person_capacity": 8,
"navigational_status": "Moored"
}
]
}

Tags (3)
0 Kudos
1 Solution

Accepted Solutions
RJSunderman
Esri Regular Contributor

Hello Geoffrey West

Looking at the JSON you illustrated it looks to me like the data object is an array of JSON objects:

"data": [
{
"id": "b2c2626d-ff0b-4892-8262-5acae60946a4",
"name": "JUPITER II",
"mmsi": 701000533,

...‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍

You probably need to add an index into your hierarchy parsing string to change

data.last_known_position.geometry.coordinates[0]

to

data[0].last_known_position.geometry.coordinates[0]

Also, I noticed that all of the negative double values seem to have an extra space between the '-' and the actual value. Quick experiments with GeoEvent Server seem to show that the extra white-space is being removed by the library used to parse the data ... I noticed https://jsonlint.com does the same thing ... but a different validator I often use triggered on these values and refused to validate the JSON to show it in a tree with collapsible nodes. 

Hope this information is helpful –

RJ

View solution in original post

1 Reply
RJSunderman
Esri Regular Contributor

Hello Geoffrey West

Looking at the JSON you illustrated it looks to me like the data object is an array of JSON objects:

"data": [
{
"id": "b2c2626d-ff0b-4892-8262-5acae60946a4",
"name": "JUPITER II",
"mmsi": 701000533,

...‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍

You probably need to add an index into your hierarchy parsing string to change

data.last_known_position.geometry.coordinates[0]

to

data[0].last_known_position.geometry.coordinates[0]

Also, I noticed that all of the negative double values seem to have an extra space between the '-' and the actual value. Quick experiments with GeoEvent Server seem to show that the extra white-space is being removed by the library used to parse the data ... I noticed https://jsonlint.com does the same thing ... but a different validator I often use triggered on these values and refused to validate the JSON to show it in a tree with collapsible nodes. 

Hope this information is helpful –

RJ