Specifying a JSON Path

For non-developers

For features that get data from a REST API such as Data Visualization, Volumetric Heatmap, and Dynamic Object, you need to specify a JSON Path to get the value in your JSON object that you wish to display.

Writing your first JSON Path

Let's try to write a JSON Path to get a value from https://random-data-api.com/api/number/random_number. It is a free REST API random number generator.

  1. Open SpatialWork and add this link to Add Data Source

  2. See how the data looks like by opening the link in your browser. It should look something like this.

// 20230726155959
// https://random-data-api.com/api/number/random_number

{
  "id": 7303,
  "uid": "b0668507-565e-4774-989b-cb7672687071",
  "number": 6181806351,
  "leading_zero_number": "0803646977",
  "decimal": 89.16,
  "normal": 52.45865251692524,
  "hexadecimal": "1e833e22223016b8",
  "positive": 1867.81113107343,
  "negative": -4588.198551269647,
  "non_zero_number": 2,
  "digit": 8
}

Note: If your browser gives you a security warning, do not worry, just proceed to the website anyway. You will see the code above.

  1. Copy and paste the JSON object (everything between the largest { }, from the 4th line) into a query-testing website such as https://www.jsonquerytool.com/. Paste it into the Input box.

  1. Try retrieving different numbers by typing in the Query box. For example,

  • $.id outputs 7303 from the JSON object

  • $.decimal outputs 8 from that JSON object

For a detailed guide on how to write JSON paths, refer to https://support.smartbear.com/alertsite/docs/monitors/api/endpoint/jsonpath.html

  1. After the output shows the data that you want, copy and paste the query into the JSON Path field in SpatialWork. It should start displaying once you save.

Last updated