FREE TOOL

JSON to Python path explorer

Paste a JSON document, such as a RESTCONF reply or an inventory file, and browse it as a tree. Select any value to get the Python expression that reaches it after data = json.loads(text), with the value's JSON type and Python type. The explorer reads the paste in this page, never runs it, and does not send it to a server. No account is required.

JSON document

This explorer runs in your browser and needs JavaScript turned on. The boxes stay locked until the page script loads, so the page cannot send anything you enter. If they stay locked, the script did not load. Turn on JavaScript or reload the page to use the explorer.

Up to 200,000 characters, 64levels of nesting and 5,000 values.

How a path is built

After data = json.loads(text), a JSON object becomes a Python dict and a JSON array becomes a list. You reach a value one bracket at a time, left to right. data["interfaces"] looks up the key "interfaces" in the top-level dict and gives a list;[0] takes the first item of that list, because Python counts from 0; and ["name"] looks up "name" in the dict that item holds. The working steps on this page spell out each lookup and the type it gives.

Why every key is in quotes

A JSON key is always a string, even when it looks like a number. In the example below, the VLAN names are under the keys "10" and "20", so the path is data["vlans"]["10"]. Writingdata["vlans"][10] raises KeyError, because the dict has no integer key 10. The explorer writes every key as a Python string in double quotes and escapes what needs it: a double quote becomes \", a backslash becomes \\, a line break becomes \n, and control and invisible formatting characters become \x, \u or \U escapes, so what you copy reads back as exactly the key in the document.

Types, null and None

Each value shows its JSON type and the Python type json.loads gives it. JSON true and false become True and False, and JSON null becomes None. A number written with a decimal point or an exponent, such as 1.0 or 1e3, becomes a float, and one written without becomes an int, so 1 and 1.0 are different types in Python even though they are equal. If an object repeats a key, json.loads keeps the last value, and the tree marks the earlier one.

To practice, find the path to the second interface's MTU in the example before you paste it, then check your answer in the explorer. The first interface's description is null, which is a value, not a missing key:data["interfaces"][0]["description"] gives None, whiledata["interfaces"][0]["mtu"] raises KeyError.

{
  "hostname": "edge-rtr01",
  "interfaces": [
    {"name": "Ethernet0/0", "enabled": true, "ipv4": "172.16.12.1/30", "description": null},
    {"name": "Ethernet0/1", "enabled": true, "ipv4": "172.16.12.5/30", "mtu": 1500}
  ],
  "vlans": {"10": "USERS", "20": "VOICE"}
}

Why this explorer has no share link

A pasted document can hold anything: device data, inventory, names or tokens. The explorer cannot tell what is safe to put in a link, so it has no share link and never writes the document or a path to the page's URL. Use Copy results or Copy the selected path to keep what you need.

What this explorer does not do

The explorer writes paths for Python's json module and its default types. It does not run the path, so it cannot tell you that your own code holds the document under another name than data. It reads strict JSON as your browser's JSON parser accepts it, so comments, trailing commas, single quotes and NaN are refused, which matches json.loads for everything except NaN and Infinity, which Python accepts by default. Numbers are shown as written in the paste. Python reads a number with a decimal point or an exponent as the nearest float, so a very precise one can print differently in Python. The tree holds at most5,000 values and 64 levels.

Sources: RFC 8259, The JavaScript Object Notation (JSON) Data Interchange Format, for the grammar and for keys being strings; Python json module documentation, for the conversion table, repeated keys and NaN; Python escape sequences, for the string quoting.