Select to view content in your preferred language

Field Calculator (RegEx?) to remove portion of JSON syntax

4040
4
11-10-2014 01:34 PM
JeremyMullins1
New Contributor III

I have the following output in my browser when I perform a json (get) query:

jQuery2112012970359064638615_1415645296091({"success": true, "vehicles": [{"agency_id": 563, "apc_status": "not_installed", "call_name": "1969", "current_stop_id": 8064840, "heading": 12, "id": 8014243, "load": null, "position": [30.549453, -87.219218], "route_id": 8002908, "segment_id": 8033424, "speed": 0.0, "timestamp": 1415654632000}]});

This is information about our school's trolley location, which we are trying to simulate in our GeoEvent Processor. When GEP accepts this information and tries to make a GeoEvent Definition out of it, I simply get "Success" and "Vehicles", with the latter having a drop-down menu style in the GED. From there, I can give the "id" value the "TRACK_ID" tag, but the "GEOMETRY" tag is nowhere to be found for "position". I figure it's the JSON's initial formatting that is causing the hiccup, and I am not sure what sort of field calculation I am supposed to perform so that I get, basically, this:

"agency_id": 563, "apc_status": "not_installed", "call_name": "1969", "current_stop_id": 8064840, "heading": 12, "id": 8014243, "load": null, "position": [30.549453, -87.219218], "route_id": 8002908, "segment_id": 8033424, "speed": 0.0, "timestamp": 1415654632000

I am hoping that GEP can understand this much easier, as it seems more logical, and create a GED with each item in " " getting its own field automatically. I have a hunch that this isn't going to happen, so what can I do to make it so that my output (eventually a constantly-updating feature service) will remove all the excess nonsense?

0 Kudos
4 Replies
ThomasPaschke
New Contributor III

Hey Jeremy,

If you specify the JSON Object Name on the input properties and set it to ‘vehicles’, GEP should only query for the features inside of this vehicle array which should be what you are looking for.

Untitled.jpg

I tried this on a Receive JSON on a REST endpoint input using your example string and it worked for me.

Untitled2.jpg

Hope that helps!

Best,

Thomas

JeremyMullins1
New Contributor III

Thomas,

That makes so much sense, and it was so simple! Now let me throw another curveball at you. If you can help me with this, I may just buy you an island.

I am not able to construct a GEOMETRY field with only "position"; the tag does not appear for that field because, as you can see, it's treated as a type: Double. How do I correct this? I assume I will either have to do some field mapping and *gulp* field calculation to a new GED, which I am horrible at. I want to tell the GEP that the position is changed to latitude and longitude and then use those as type: GEOMETRY in the GED so that I can update a feature service in real time.

So I guess my questions are these:

1. What do I do to turn "position" from the JSON feed to something I can turn into points updating in real-time on a feature service?

2. Would it be possible to even do this? For example, would I have to create a Poll an External Site for JSON, use the correct processors, input that information into an output connector that can construct those two now separated fields back into one so that I can then create another output for a feature service (which, as I type this, seems like it may not even be possible at this point)?

3. Am I making this ridiculously complicated because I am a GEP n00b?

0 Kudos
ThomasPaschke
New Contributor III

Hey Jeremy,

you are right, the position field is not in a suitable format for GeoEvent to recognize it as a geometry. As you said you would have to get the X and Y values from the position field and create your own geometry field from this values. It is possible but a little bit tricky.


1. Create a fixed GeoEvent definition for your input (copy the aut generated one and change the settings on the input to use this one) which receives the position as a string instead of a double.

Untitled.jpg

2. Now you can look up the X and Y value from this string using two Reg-Ex field calculators with the pattern " -\d+.\d* " for X and " (?<=\[)\d+.\d* " for Y and save these values as doubles to new fields.

3. Finally you can use a field calculator to create your own geometry field in the json format using a expression like '{"x":'+ X +',"y":'+ Y +'}' and make the new field of type geometry.

Untitled2.jpg

This way it works for me. I hope it helps.

Best,

Thomas

JeremyMullins1
New Contributor III

Thomas,

I want to thank you again for all your help. This worked perfectly. However, I wasn't able to get it to output to a feature service, which was my final goal. I unfortunately didn't have enough time to troubleshoot the problem more. Thanks again for all your help.

0 Kudos