Skip to main content
Solved

Converting JSON nested point coordinates to lines

  • December 13, 2023
  • 4 replies
  • 142 views

mzondervan
Contributor

I'm using the HTTPCaller to read in an MDS data feed that I would like to convert to an AGOL line feature by connecting the points together from the "route" attribute. I'm able to extract the attributes for each trip in the dataset using the JSON Fragmenter and JSON Extractor, but I'm getting stuck on creating the geometry. How can I take each point coordinate from a trip and connect them into a line and keep the trip attributes associated with it? Example of the JSON format is attached.

 

Best answer by takashi

Hi @mzondervan ,

Alternatively, you can read every Feature object as GeoJSON features directly with JSONFragmenter, since the "route" object is a GeoJSON document.

  • JSON Query: json["data"]["trips"][*]["route"]
  • Fragment as Format: GEOJSON

jsonfragmenter-parameters

This post is closed to further activity.
It may be an old question, an answered question, an implemented idea, or a notification-only post.
Please check post dates before relying on any information in a question or answer.
For follow-up or related questions, please post a new question or idea.
If there is a genuine update to be made, please contact us and request that the post is reopened.

4 replies

ctredinnick
Supporter
Forum|alt.badge.img+19
  • Supporter
  • December 14, 2023

imageBecause there could be multiple trips, and you need attributes from the top level and also from each point, it's an awkward series of json transformers.

 

JSONFragmenter by json["data"]["trips"][*]

Then JSONExtractor to extract the route and device with json["route"] and json["device_id"]. Perhaps remove the original json attribute at this point if it's going to be too large.

Then fragment that route into point parts with json["features"][*]

Then JSONExtractor the attributes for each point json["geometry"]["coordinates"][0] and json["geometry"]["coordinates"][1] and json["properties"]["timestamp"]. If you don't need the time you can ignore that.

Then VertexCreator, and lastly a LineBuilder, grouping by the device_id


takashi
Celebrity
  • Best Answer
  • December 14, 2023

Hi @mzondervan ,

Alternatively, you can read every Feature object as GeoJSON features directly with JSONFragmenter, since the "route" object is a GeoJSON document.

  • JSON Query: json["data"]["trips"][*]["route"]
  • Fragment as Format: GEOJSON

jsonfragmenter-parameters


ctredinnick
Supporter
Forum|alt.badge.img+19
  • Supporter
  • December 14, 2023

Hi @mzondervan ,

Alternatively, you can read every Feature object as GeoJSON features directly with JSONFragmenter, since the "route" object is a GeoJSON document.

  • JSON Query: json["data"]["trips"][*]["route"]
  • Fragment as Format: GEOJSON

jsonfragmenter-parameters

Aha, fragment as format GeoJSON. I didn't know that was an option, thanks!


mzondervan
Contributor
  • Author
  • Contributor
  • December 14, 2023

Hi @mzondervan ,

Alternatively, you can read every Feature object as GeoJSON features directly with JSONFragmenter, since the "route" object is a GeoJSON document.

  • JSON Query: json["data"]["trips"][*]["route"]
  • Fragment as Format: GEOJSON

jsonfragmenter-parameters

Thank you @takashi, this works perfectly.