PLEASE Help! JSON-API: Parsing Data into Widget

Hello!

I need help with parsing values from a API Request as variables into widgets.

How can I parse the values from “features/properties/…” in Variables?

Here is the JSON answer from the API-Request:

Preformatted textCache-Control:must-revalidate
Connection:keep-alive
x-amz-meta-cachetime:210
Vary:Accept-Encoding
Date:Sun, 27 Sep 2020 18:02:14 GMT
Content-Length:19627
x-amz-meta-contentlastmodified:2020-09-27T01:54:21.849Z
Server:openresty
Content-Encoding:gzip
Content-Type:application/json
Content-Disposition:attachment; filename=“RKI_Corona_Landkreise.geojson”
Etag:“3279d84674a2add00fdd8c434724b3a7”
Last-Modified:Sun, 27 Sep 2020 02:13:43 GMT

{
“crs” : {
“type” : “name”,
“properties” : {
“name” : “urn:ogc:def:crs:OGC:1.3:CRS84”
}
},
“features” : [
{
“type” : “Feature”,
“properties” : {
“SN_L” : “05”,
“SHAPE_Length” : 2.3945198859124219,
“cases_per_100k” : 256.23604775308161,
“last_update” : “27.09.2020, 00:00 Uhr”,
“recovered” : null,
“BEZ” : “Kreis”,
“SN_V1” : “00”,
“deaths” : 32,
“cases_per_population” : 0.25623604775308162,
“IBZ” : 42,
“ADE” : 4,
“BEM” : “–”,
“NBD” : “nein”,
“SN_R” : “9”,
“SDV_RS” : “059620032032”,
“cases” : 1056,
“BL” : “Nordrhein-Westfalen”,
“BL_ID” : “5”,
“SN_V2” : “00”,
“GF” : 4,
“RS” : “05962”,
“AGS_0” : “05962000”,
“GEN” : “Märkischer Kreis”,
“KFL” : 1061.0599999999999,
“DEBKG_ID” : “DEBKGDL20000E12D”,
“EWZ” : 412120,
“FK_S3” : “R”,
“SHAPE_Area” : 0.13665048152792683,
“OBJECTID” : 112,
“BSG” : 1,
“SN_K” : “62”,
“NUTS” : “DEA58”,
“SN_G” : “000”,
“death_rate” : 3.0303030303030303,
“cases7_per_100k” : 6.3088420848296609,
“WSK” : “2009/01/01 00:00:00.000”,
“RS_0” : “059620000000”,
“county” : “LK Märkischer Kreis”,
“AGS” : “05962”
},

Can you provide the source url?

Also, I’m not sure I understand your question. Are looking to assign certain properties to a variable or filter the result into a variable such that the variable is bound to an array of just a single property value?

The source url is:

https://opendata.arcgis.com/datasets/917fc37a709542548cc3be077a786c17_0.geojson?where=RS%20%3D%20'05962'

Here is the script i am trying to realize:

// Variables used by Scriptable.
// These must be at the very top of the file. Do not edit.
// icon-color: deep-green; icon-glyph: user-md;
const url = `https://opendata.arcgis.com/datasets/917fc37a709542548cc3be077a786c17_0.geojson?where=RS%20%3D%20%2705962%27 `
const req = new Request(url)
const res = await req.loadJSON()

if (config.runsInWidget) {
  // create and show widget
  let widget = createWidget("Corona", `${res.*features.properties.cases*} Cases`, `${res.*features.properties.cases7_per_100k*} Cases per 100k in last 7 Days`, "#53d769")
  Script.setWidget(widget)
  Script.complete()

What do those parameters to createWidget() do? (I’m learning here - and I associate dollar signs with JQuery - which this probably isn’t.)

Expression interpolation in a template string.

So above, they are just evaluated parts of a text string passed into the standard widget parameters.

1 Like

Is this what you’re looking for?

let cases = res.features[0].properties.cases_per_population
let per1000 = res.features[0].properties.cases7_per_100k

Man, it’s perfect! THANK YOU VERY MUCH!

I have just one more question…:wink::

How can I convert “let per1000 = res.features[0].properties.cases7_per_100k” data into a (number) format with comma and two decimal places?

I would be very happy to receive further help!

per1000.toFixed(2)

Thank you, again! It works like a charm!:+1:t2: