I have a geojson live feed in Velocity. The data comes in fine, however my main core of attrbutes are all nested together in one attribute column. I know in Velocity, I can add fields, but I do not know the arcade functions needed to break down the nested attributes into their own new fields. Can someone help me with the arcade?
currentConditions | [{"id":3023658,"conditionId":17,"conditionDescription":"3 - dry","userName":"","startTime":1729576800213,"endTime":4883216432298,"confirmationTime":1729616432298,"updateTime":1729576800213,"confirmationUserName":"","sourceType":"OPERATOR","additionalData":null},{"id":3026261,"conditionId":47,"conditionDescription":"forecast text included","userName":"","startTime":1729616555832,"endTime":1729638039767,"confirmationTime":1729616439767,"updateTime":1729616439767,"confirmationUserName":"","sourceType":"NDFD","additionalData":"Clear skies. Wind gusts of up to 21 mph are expected."}] |
Hi @NateRogers1- I think there are 2 ways that you could approach this:
2. Go the route that you initially suggested an use some Arcade. You could use the Calculate Field tool and set up multiple calculations to parse your field, currentConditions, into separate fields. I'm guessing your field currentConditions is a String field, so you need to first convert it into an array, which then makes parsing a lot easier. Here's some example Arcade:
// my field called 'placeholder' contains the array with nested objects. This field is a Text field
// use fromJSON to convert text into an Array
var currentConditions = fromJSON($feature.placeholder);
// array is stored in var currentConditions. This contains 2 objects
// access first object (at index value 0), then access value associated with field 'conditionId'. This returns 17
var conditionId_1 = currentConditions[0]['conditionId']
// access second object (at index value 1), then access value associated with field 'additionalData'. This returns 'Clear skies. Wind...'
var additionalData_2 = currentConditions[1]['additionalData'];
return additionalData_2;
-Joanna
Hi Joanna,
Thank you so much for taking the time to help. I want to keep the feed as a geojson because there are a mix of points and polylines and if I turn the feed into a json, those extra coordinates needed for the lines disappear as it only becomes a begin xy to end xy and doesnt pick up all the middle verticies.
I am completely terrible at Arcade, do you know of any resources or would be able to help parse out more what the arcade function would look like? Thanks!!!
Hi Nate- I totally understand, Arcade can be a little bit of a learning curve.
I would start with the function reference documentation here. If you're looking to learn more about parsing data returned in an array, maybe first focus on the Array functions area first.
Another quick resource that I like to use is the ArcGIS Arcade Playground. In the screenshot below, you can see how I took the Arcade snippet that I provided, and replaced the currentConditions variable with the text that you initially provided. Then I'm able to execute the Run the expression and change my expression to change the output results.
Some other Velocity-specific resources for Arcade:
Using Arcade in ArcGIS Velocity
Best practices for Arcade expressions in ArcGIS Velocity
-Joanna
so I was struggling with this and I had an idea that seems to work. Instead of struggling with the arcade, I can connect to the feed twice, once as a geojson to get the geometry but exclude out all attributes except the id field, then I can create a new feed as a JSON so I can flatten the attributes but with no geometry then in Velocity I can use the join field to join the geojson ID field with the JSON id field so I get both geojson geometries with the fixed attributes.