Hi, is it possible to parse data from a json link using Arcade? Its for a popup in arcgis online. I have figured out how to get the specific field I need, but how do I download and store a json link. https://askeladden.ra.no/arcgis/rest/services/Distribusjon/Kulturminner/MapServer/8/query?where=Loka...
It seems XMLHttpRequest is not supported in Arcade..
This is what I have so far:
Better formatting:
https://gist.github.com/OterLabb/2a43707c470499b6500b909a0ce69f29
var fromJSON = [
{
"displayFieldName": "LID",
"fieldAliases": {
"Beskrivelse": "Beskrivelse"
},
"fields": [
{
"name": "Beskrivelse",
"type": "esriFieldTypeString",
"alias": "Beskrivelse",
"length": 2147483647
}
],
"features": [
{
"attributes": {
"Beskrivelse": "Fornminne: Gravrøys, klart markert og meget tydelig i terrenget. Bygget av kuppelstein med tverrmål opptil 0,5 m. Røysa er rund, og har dels bratte, dels slake sider pga at sentrum og deler av sidene er sterkt omrotet ved eldre graving. Pga den sterke omrotingen er røysas omkrets noe uregelmessig. Overflaten i røysa er lagt med småstein, slik at sidene blir jevne og pene. Bevokst med mose. Mål: diameter 18 m, høyde ca 2 m. Røysa ligger forbausende lavt. Med noe høyere vannstand ser røysa ut til å bli liggende på et lite nes. Ca 20 m S for røysa er bakken meget ujevn, slik at det danner seg voller og hauger. En formasjon kan se ut som en rund haug (diameter 6 m, høyde 0,5 m), med grop i toppen. Det er imidlertid en gammel trerot og to tilbakeveltede rotvelter som kan bidra til å gi inntrykk av haug. Neppe gravhaug. 5 m V for denne er der en N-S-gående, noe butt voll, (ca 12 m lang, 1,5-2 m bred, 0,3 m høy). I S-del støter det til fra Ø en ujevn ØSØ-VSV-gående lignende voll (S for haugen). Også i vollen er der gamle trerøtter, og rotvelter inntil. Det er meget vanskelig å få noen oversikt over formasjonene uten å torve av området."
}
}
]
}];
var newString = Concatenate(fromJSON[0].features[0].attributes.Beskrivelse) // output: Beskrivelse
newString
Solved! Go to Solution.
Currently, it is not possible to make external calls and parse the returning json response. The only thing you can do (although that is not what you are after) is include a json string (hardcoded) in your Arcade expression and parse it there. This will be static and not very useful. If you have an attribute that contains a json string you can parse that in the Arcade expression, but that is a far as you can get at this moment. However, external calls may be on the agenda for future releases.
Currently, it is not possible to make external calls and parse the returning json response. The only thing you can do (although that is not what you are after) is include a json string (hardcoded) in your Arcade expression and parse it there. This will be static and not very useful. If you have an attribute that contains a json string you can parse that in the Arcade expression, but that is a far as you can get at this moment. However, external calls may be on the agenda for future releases.
Ok, thanks for answering. This layer im calling to get json results from is another arcgis layer, is there a way to call another layer in arcgis online? Something like: $feature.fromAnohterLayer where LocationID = 29
You could create a JavaScript application that does this kind of thing, but as mentioned before at this moment not in Arcade. I have been told that Esri is working to enable reading related data, but since Arcade is "dynamic", each request to external data could have a negative impact on performance. So, each time you pan or zoom, it will make the requests to build up the desired result. The more complex this result is achieved, the more time it will take to get that result.
Xander, you mentioned hardcoding a json string and parsing in Arcade. I grab activities related to a record from a Rest API (https ://mylink .com/API/get/ ?APIkey=????&id=[1234]) Record 1234 can have multiple activities and I would like to display them in the popup. Is this possible with what you mentioned above? If so, are there any samples of arcade expressions that do this?
Thank you in advance,
Hi Adam Cottrell ,
As far as I know, this is not possible yet. Doing REST calls from Arcade is on the roadmap, so it will come, but I don't have an ETA.
Seems like you have two questions - how to download data from a URL and how to parse JSON. Regarding the latter, you can parse a JSON dictionary into an Arcade dictionary.
https://developers.arcgis.com/arcade/function-reference/dictionary_functions/#dictionary2
I am writing data out to a hosted feature layer that I want to format with Arcade in the pop-up, so I have full control. No idea what I'd do if I had to read an Array, but I guess I'll just format my data as a Dictionary.
FromJSON worked for me to convert a JSON string (a JSON Array of JSON Objects) into an Arcade Array needed for media popup, https://developers.arcgis.com/arcade/function-reference/dictionary_functions/#fromjson