Skip to content

JsonView

A collapsible tree view of a JSON value: ▸/▾ rows expand and collapse in place, and values are colored by type. Invalid source is rendered as a parse-error state instead of throwing.

Import: package:fleury/fleury.dart, or package:fleury/fleury_core.dart in browser code.

JsonView(
value: const <String, Object?>{
'name': 'fleury',
'version': '1.0.0',
'web': true,
'targets': <String>['terminal', 'dom', 'serve'],
},
defaultExpandedDepth: 2,
)

Up and Down move the selected row; PageUp, PageDown, Home, and End jump. Right expands a collapsed object or array or, on an expanded one, steps into its first child. Left collapses an expanded one or steps out to the parent. Enter or a click expands or collapses an object or array. Ctrl+C copies the selected node as JSON, or only its visible row when copyOptions sets JsonViewCopyMode.line.

The viewer bounds its own height: it renders at most maxVisible rows (fewer for a shorter document) and scrolls the rest, so it composes directly inside a Column or any other unbounded slot. Wrap it in an Expanded or a SizedBox to give it a different height.

ParameterTypeDefaultDescription
value:Object?requiredAlready-materialized JSON-compatible value wrapped in document.
controller:JsonViewController?—External expansion, selection, and visible-range controller.
focusNode:FocusNode?—Focus node used for keyboard navigation.
autofocus:boolfalseWhether the viewer should request focus when mounted.
semanticLabel:String'JSON'Semantic label (the accessibility name; not rendered) for the JSON viewer.
defaultExpandedDepth:int1Depth expanded by default before user-controlled collapse state applies.
maxLineLength:int?1000Cuts each displayed row, indentation included, to this many characters, ending it with …; null never cuts. Copying a node still copies all of its JSON.
maxVisible:int12Maximum visible JSON rows before the viewer scrolls. More
copySelection:booltrueWhether Ctrl+C (and the semantic copy action) copies the selected node, or its row if copyOptions says so.
copyOptions:JsonViewCopyOptionsconst JsonViewCopyOptions()Clipboard/export options for copied JSON text.
onCopy:void Function(JsonViewCopyResult result)?—Called after a copy attempt completes.
  • maxVisible: This is what bounds the viewer’s height in an unbounded slot (a Column child, say); the internal list cannot window its rows without one.

Creates a viewer from a parsed or already-materialized JsonViewDocument.

A document that retains a parse error renders its invalid-document state.

ParameterTypeDefaultDescription
document:JsonViewDocumentrequiredParsed or already-materialized JSON document to render.
controller:JsonViewController?—External expansion, selection, and visible-range controller.
focusNode:FocusNode?—Focus node used for keyboard navigation.
autofocus:boolfalseWhether the viewer should request focus when mounted.
semanticLabel:String'JSON'Semantic label (the accessibility name; not rendered) for the JSON viewer.
defaultExpandedDepth:int1Depth expanded by default before user-controlled collapse state applies.
maxLineLength:int?1000Cuts each displayed row, indentation included, to this many characters, ending it with …; null never cuts. Copying a node still copies all of its JSON.
maxVisible:int12Maximum visible JSON rows before the viewer scrolls. More
copySelection:booltrueWhether Ctrl+C (and the semantic copy action) copies the selected node, or its row if copyOptions says so.
copyOptions:JsonViewCopyOptionsconst JsonViewCopyOptions()Clipboard/export options for copied JSON text.
onCopy:void Function(JsonViewCopyResult result)?—Called after a copy attempt completes.

Creates a viewer by parsing JSON source.

Invalid JSON is retained as a document error and rendered by the viewer instead of being thrown from this constructor.

ParameterTypeDefaultDescription
sourceStringrequiredJSON source parsed into a document before the widget is mounted.
controller:JsonViewController?—External expansion, selection, and visible-range controller.
focusNode:FocusNode?—Focus node used for keyboard navigation.
autofocus:boolfalseWhether the viewer should request focus when mounted.
semanticLabel:String'JSON'Semantic label (the accessibility name; not rendered) for the JSON viewer.
defaultExpandedDepth:int1Depth expanded by default before user-controlled collapse state applies.
maxLineLength:int?1000Cuts each displayed row, indentation included, to this many characters, ending it with …; null never cuts. Copying a node still copies all of its JSON.
maxVisible:int12Maximum visible JSON rows before the viewer scrolls. More
copySelection:booltrueWhether Ctrl+C (and the semantic copy action) copies the selected node, or its row if copyOptions says so.
copyOptions:JsonViewCopyOptionsconst JsonViewCopyOptions()Clipboard/export options for copied JSON text.
onCopy:void Function(JsonViewCopyResult result)?—Called after a copy attempt completes.

JsonView is defined in packages/fleury/lib/src/catalog/json_view.dart.

Category: Text & content · All widgets