Skip to content

The example JSON document ​

In every runnable example on this site, the variable doc holds this document. It is like the doc a check rule receives: the report of one device.

The example JSON document is made up

All names and values in it are invented; only the shape is typical of the JSON a device sends.

Where to find it ​

  • In the homework repository: data/sample-asset.json. Open it in VSCode to see it with colours and to fold the parts you do not need.
  • The tasks load it with require (explained in session 9): const doc = require("../../data/sample-asset.json");
  • The document grows during the course: a lecture adds a new part when it needs one (for example inventory.modules in lecture 6). This page always shows the current version. After git pull --no-rebase --no-edit upstream main your copy is the same.

The whole document ​

Open it in the viewer:

Explore the data files

A click on a file name opens the file in a viewer. Tree shows the levels of the document: open and close them with the arrows. Paths lists every value with its full path, and the filter finds a key or a value. Tables shows every list of records (and every dictionary of records) as a table. Text shows the file as it is, with line numbers. A click on a value shows the path to it the way your code reads it - doc.inventory.modules["12_4.20"].status - and Copy copies the path. Download saves the file.

json
{
  "_note": "MADE-UP example JSON document for the course. All names, ids and values are invented; only the shape is typical of the JSON a device sends.",
  "status": {
    "device_alias": "D7F3A9C21E40B815",
    "epoch": "1791770402"
  },
  "overview": {
    "model": "XR-220",
    "serial_number": "SN4X7Q92",
    "version": "4.2.1.7"
  },
  "alerts": {
    "CHK-0132": {
      "raised": "yes"
    }
  },
  "inventory": {
    "device_alias": "D7F3A9C21E40B815",
    "details": {
      "remote_login_cert_set": "no",
      "remote_login_configured": "yes",
      "remote_login_enabled": "yes",
      "remote_login_pwd_set": "no",
      "remote_login_type": "central",
      "bandwidth": "",
      "power_saving": "on",
      "locale": "en_US",
      "ntp_ip_address": "10.0.0.1",
      "device_id": "D7F3A9C21E40B815",
      "device_alias": "D7F3A9C21E40B815",
      "firmware_level": "4.2.1.7 (build 412.17.2607151200)",
      "consoles": "CON-01;CON-02",
      "settings": "SA=2,SG=1,SN=2"
    },
    "extended_info": {
      "json": {
        "data": {
          "system": {
            "name": "LAB-DEV-01"
          }
        }
      }
    },
    "features": [
      "dedup",
      "compression",
      "encryption"
    ],
    "enclosures": [
      {
        "id": "ENC-01",
        "type": "SSD-24",
        "firmware": "2.14",
        "state": "normal"
      },
      {
        "id": "ENC-02",
        "type": "SSD-24",
        "firmware": "2.10",
        "state": "normal"
      },
      {
        "id": "ENC-03",
        "type": "HDD-12",
        "firmware": "2.14",
        "state": "degraded"
      },
      {
        "id": "ENC-04",
        "type": "HDD-12",
        "firmware": "2.10",
        "state": "normal"
      }
    ],
    "modules": {
      "12_4.20": {
        "status": "OK",
        "installed": "2025-11-20"
      },
      "12_4.08": {
        "status": "OK",
        "installed": "2025-11-21"
      },
      "47_1.07": {
        "status": "FAILED",
        "installed": "2025-11-20"
      }
    },
    "labels": {
      "Firmware Version": "4.2.1.7",
      "Last Check": "12-10-2026 18:25:23",
      "Site": "Demo Lab"
    }
  }
}

console.log(doc) prints an object on one line, and shows the deeper levels only as [Object]. To see a part of the document indented, turn it into text with JSON.stringify(value, null, 2) (2 = two spaces per level; more about JSON in session 9):

js
console.log(JSON.stringify(doc.overview, null, 2));
console.log(JSON.stringify(doc.inventory.enclosures[0], null, 2));
Edit the code and run it again

Change the path and press Run to look at another part, or print the whole document with JSON.stringify(doc, null, 2). console.dir(doc, { depth: null }) also shows every level (on one line), and console.table(doc.inventory.enclosures) shows a list of records as a table (session 7).

Every Run starts with a fresh copy

An example that changes doc (adds, changes or deletes a key) changes only its own copy. The file and the other examples on the page stay the same.

The other data files of the homework ​

Some tasks use bigger made-up documents, in the other shapes the real data comes in. They are in the same folder data/ of the homework repository:

FileShapeUsed in
a flat list of 79 key/value records { group, item, code, label, value } that must be groupedsessions 4, 7 and 8
dictionaries keyed by ids, with dots in the keys; dates and versions in mixed formatssessions 5 - 8
the same deep document twice: nested (_source) and as a flattened export (fields, where every key is a whole path: "a.b.c": [value])sessions 6 and 8
reports/five small reports in the shape of doc, for running a rule on a folder: fine, with problems, another model, with missing parts, and not valid JSON - on purposesessions 9 and 10

Each task file says at the top which file it uses and what to look for in it.

Created for