Skip to content
FALCON CORETECHNOLOGIES

// Lesson 48 of 49 · Automation and programmability

Reading and writing JSON

JSON data types, objects and arrays, nesting, and the syntax mistakes that break it.
1 min read#json#data-formats

JSON (JavaScript Object Notation) is the data format most network APIs use. It is plain text, easy for people to read and for programs to parse.

Building blocks

{
  "hostname": "SW1",
  "managementIp": "192.168.99.11",
  "uptimeDays": 41,
  "stackMember": false,
  "location": null,
  "vlans": [10, 20, 99],
  "interfaces": [
    { "name": "GigabitEthernet1/0/1", "vlan": 10, "status": "up" },
    { "name": "GigabitEthernet1/0/2", "vlan": 20, "status": "down" }
  ]
}
Type Example
Object { "key": value, ... } — unordered key/value pairs
Array [ value, value ] — ordered list
String "SW1" — always double quotes
Number 41, 3.5 — no quotes
Boolean true / false — lowercase, no quotes
Null null

Keys are always strings in double quotes. Values can be any type, including nested objects and arrays.

Reading it

To find the status of the second interface: start at the outer object → key interfaces → array element 1 (counting from 0) → key status → "down". In Python that is data["interfaces"][1]["status"].

Common mistakes

  • Single quotes: 'SW1' is invalid.
  • A trailing comma after the last item: [10, 20, 99,] is invalid.
  • Missing commas between items, or unquoted keys.
  • Comments — JSON has none.

Paste suspicious output into a JSON validator or use python -m json.tool file.json to find the error.

Other formats you will meet

  • YAML — indentation-based, used by Ansible playbooks and many config files.
  • XML — tag-based, used by NETCONF.

Key points

  • Objects {} hold key/value pairs; arrays [] hold ordered values.
  • Strings and keys use double quotes; true, false, null are lowercase.
  • Arrays are indexed from 0.
  • No trailing commas, no comments.

Sign in to save your lesson progress across devices. You can read every published lesson without an account.