I am using an attribute field to store the JSON output result of an API call. I want to use the JSON content to populate information in a pop-up for a web map using Arcade with ArcGIS Online.
A little background. I have a python script that uses `requests` to make an API call to our city's 311 service. The resulting JSON response is stored in a field of a hosted feature service named 'Comments'. These are comments made by the public or city workers who are responding to 311 calls.
I want to use Arcade to convert the contents of the field to a Dictionary or Array, but I am having no luck. Here is sample dictionary of a text string from the Comments field:
/*Basic returns for targeting keys in dictionary list from FEATURE
-------------------------------------------------------------------------*/
var comments = $feature.Comments
return comments[0].date
// returns Test execution error: Execution error - Cannot access value using a key of this type. Verify test data.
return comments[0].comment
// returns Test execution error: Execution error - Cannot access value using a key of this type. Verify test data.
However, if I name a variable that contains the contents of the Comment without populating from a field, I have no issues accessing keys in the dictionary:
var comments = [{'date': '2025-12-29', 'comment': 'Code Enforcement has received your service request (#CRM-25001496).', 'visibility': 'Public'}, {'date': '2025-12-29', 'comment': 'This issue was recategorized from Unsafe Sidewalks or Rights-Of-Way to Encampment Activity.', 'visibility': 'Public'}, {'date': '2025-12-29', 'comment': '7 day notice posted. Reporting party has been notified. ', 'visibility': 'Public'}, {'date': '2025-12-29', 'comment': 'CRM-25001496 on CentralSquare Community Development abandoned and now managed on SeeClickFix due to recategorization.', 'visibility': 'Internal'}, {'date': '2025-12-30', 'comment': 'CWB Street Outreach was able to make contact and provide resources and information to individuals', 'visibility': 'Public'}, {'date': '2025-12-30', 'comment': 'CWB Street Outreach was able to make contact and provide resources and information to individuals ', 'visibility': 'Internal'}, {'date': '2026-01-06', 'comment': 'We have completed your request. Thank you for your submission.', 'visibility': 'Public'}]/*Basic returns for targeting keys in dictionary list from VARIABLE
-------------------------------------------------------------------------*/
return comments[0].date
// returns text: "2025-12-29"
return comments[0].comment
// returns text: "Code Enforcement has received your service request (#CRM-25001496)."
I have read in other forums that API calls are not possible from inside Arcade for web map pop-ups. So I am trying to create a work around where Arcade can read the JSON response from the 'Comments' field. I am not sure why these two scripts create a different result if the content of the Comment is identical. Any ideas for a better work-around or a Arcade solution are appreciated
Hi @aolson,
Arcade treats the field data as a raw String, whereas your hardcoded variable is interpreted as a live Object. You need to wrap your field attribute in the FromJSON() function to convert that text into a searchable dictionary.
You can try the code below and it should work.
var comments = FromJSON($feature.Comments);
return comments[0].comment;
The problem you're running into is the comments attribute in your feature is a text string and not JSON text.
"[{'date': '2025-12-29', 'comment': 'Code Enforcement has received your service request (#CRM-25001496).', 'visibility': 'Public'}, {'date': '2025-12-29', 'comment': 'This issue was recategorized from Unsafe Sidewalks or Rights-Of-Way to Encampment Activity.', 'visibility': 'Public'}, {'date': '2025-12-29', 'comment': '7 day notice posted. Reporting party has been notified. ', 'visibility': 'Public'}, {'date': '2025-12-29', 'comment': 'CRM-25001496 on CentralSquare Community Development abandoned and now managed on SeeClickFix due to recategorization.', 'visibility': 'Internal'}, {'date': '2025-12-30', 'comment': 'CWB Street Outreach was able to make contact and provide resources and information to individuals', 'visibility': 'Public'}, {'date': '2025-12-30', 'comment': 'CWB Street Outreach was able to make contact and provide resources and information to individuals ', 'visibility': 'Internal'}, {'date': '2026-01-06', 'comment': 'We have completed your request. Thank you for your submission.', 'visibility': 'Public'}]"Regular JavaScript has the JSON.parse() method, which allows you to convert a string like that into JSON, but Arcade doesn't have that functionality.
Could you create a table from the API call and use that in a one-to-many relationship to get the related records for that feature?