JSON
The JSON widget displays JSON data in an interactive, expandable tree view. It is useful for inspecting nested structures such as API responses, configuration files, model outputs, or logs.
You can pass JSON content as:
- a Python
dict/list(it will be serialized automatically), or - a JSON
string(it will be parsed in the frontend).
Basic Usage
Section titled “Basic Usage”Display a Python dictionary:
import mercury as mr
mr.JSON( json_data={"b": [1, 2, 3], "c": ["a", "b"]}, label="Payload", level=2)Display a JSON string:
import mercury as mr
mr.JSON( json_data='{"name": "Alice", "age": 30}', label="User", level=1)Expand Level
Section titled “Expand Level”Use level to control how many levels are expanded initially.
level=0— fully collapsedlevel=1— expand the top level (default)level=2— expand two levels, etc.
import mercury as mr
mr.JSON( json_data={"a": {"b": {"c": 123}}}, level=3)Layout
Section titled “Layout”Use position to control where the widget is displayed:
"sidebar"— in the sidebar"inline"— directly in the notebook flow (default)"bottom"— after all notebook cells
import mercury as mr
mr.JSON( json_data={"status": "ok"}, position="sidebar")JSON Props
Section titled “JSON Props”json_data
Section titled “json_data”type: dict | list | string | None
JSON content to display.
- If
dictorlist, it is serialized to JSON automatically. - If
string, it is parsed as JSON in the frontend. - If
None,{}is displayed.
type: string
Optional label displayed above the viewer.
Default: ""
type: int
Initial expand level.
Default: 1
position
Section titled “position”type: "sidebar" | "inline" | "bottom"
Controls where the widget is rendered.
Default: "inline"
type: string
Unique identifier to distinguish widgets with identical arguments.
- The JSON viewer expects valid JSON types:
objects (dict), arrays (list), strings, numbers, booleans, and
null. - Python-only types like
setare not valid JSON and should be converted first (for example:list(my_set)).