json-viewer only.Expand description
A JSON document shown as rows that expand and collapse.
State flattens a serde_json::Value into nodes, or parses JSON
text with State::parse and keeps the error when it is not valid. It
holds which objects and arrays are expanded, the highlighted node and
the search. Its update handles pointer and keyboard
navigation, expanding everything or to a depth, searching and copying.
Objects and arrays show how many members they hold, {3} or [12].
Values are coloured by type from the theme’s Tokens, see syntax,
and a long value ends in an ellipsis on one line. Copy it to read it in
full. The view only builds the rows in view, so a document with
thousands of nodes stays quick.
Copying never touches the clipboard itself: Output::CopyValue holds
the value as pretty-printed JSON and Output::CopyPath its path, such
as $.users[2].name, for the app to write. Paths start at $, the
document, and use ["key"] for keys that are not plain identifiers.
The viewer resolves its keys through a Keymap of Actions while
it has focus, which it takes when pressed; see default_keymap.
Structs§
- Json
Viewer - A JSON viewer builder. Convert it into an
Elementto render. - NodeId
- A node in the document, numbered in document order.
- Parse
Error - Why JSON text could not be read.
- RowStyle
- The colours of a row.
- State
- The document, what is expanded and highlighted, and the search.
- Status
- How a row is shown.
- Syntax
- The colours of keys, values and punctuation.
Enums§
- Action
- What a viewer keyboard shortcut does.
- Event
- Everything that changes a viewer.
- Kind
- The type of a JSON value.
- Menu
Item - An entry of the context menu from
menu. - Output
- What the app may need to act on after an
Event. - Segment
- How a node is reached from its parent.
Constants§
- INDENT
- Width of one level of indentation, which is also the chevron’s slot.
- KEY_
WIDTH - The widest a key gets before it ends in an ellipsis, by default.
- ROW_
HEIGHT - Height of every row, as in a menu.
- SEARCH
- The id of the search box, unless
State::with_search_idsets another.
Functions§
- default_
keymap - The default viewer shortcuts:
- focus_
search - Focuses the search box of
state’s viewer, in answer toOutput::FocusSearch. - frame_
style - The border around the rows, as the property grid and data table have.
- json_
viewer - Renders
state. Withouton_eventit renders disabled. - match_
label - The text beside the search box: “3 of 12” for the current match of all matches, “12 found” before one is current, “None” when nothing matches, and empty without a search.
- menu
- A context menu to pass to
JsonViewer::context_menu: copy the value or its path, and expand or collapse everything inside it. Turn the chosen entry into an event withMenuItem::event. - row_
style - Resolves a row’s colours. The viewer selects nothing, so the highlighted row only carries a ring, and only while the viewer has focus. Search matches take a tint of the warning colour, stronger on the current one.
- syntax
- Resolves the syntax colours from the theme: strings take the success colour, numbers the warning colour and booleans the primary colour, drawn semibold so they stand apart from keys. In light themes strings and numbers are darkened towards the text so they stay readable on a white page.
- value_
colour - The colour of a value of this kind.
- value_
font - The font of a value of this kind: semibold for booleans, so they stand apart from keys when the primary colour is close to the text colour.