egui_json_tree

An interactive JSON tree visualiser for egui, with search and highlight functionality

9 releases (breaking)

new 0.7.1 Oct 6, 2024
0.6.0 Jul 7, 2024
0.5.0 Mar 26, 2024
0.2.0 Nov 23, 2023

#99 in GUI

Download history 701/week @ 2024-06-16 543/week @ 2024-06-23 497/week @ 2024-06-30 497/week @ 2024-07-07 578/week @ 2024-07-14 492/week @ 2024-07-21 463/week @ 2024-07-28 676/week @ 2024-08-04 645/week @ 2024-08-11 770/week @ 2024-08-18 677/week @ 2024-08-25 721/week @ 2024-09-01 1031/week @ 2024-09-08 1519/week @ 2024-09-15 1333/week @ 2024-09-22 1181/week @ 2024-09-29

5,081 downloads per month

MIT/Apache

64KB
1.5K SLoC

egui_json_tree

Latest version Documentation Build Status MIT Apache

An interactive JSON tree visualiser for egui, with search and highlight functionality.

Search Example

Usage

let value = serde_json::json!({ "foo": "bar", "fizz": [1, 2, 3]});

// Simple:
JsonTree::new("simple-tree", &value).show(ui);

// Customised:
let response = JsonTree::new("customised-tree", &value)
    .style(JsonTreeStyle {
        bool_color: Color32::YELLOW,
        ..Default::default()
    })
    .default_expand(DefaultExpand::All)
    .abbreviate_root(true) // Show {...} when the root object is collapsed.
    .toggle_buttons_state(ToggleButtonsState::VisibleDisabled)
    .on_render(|ui, ctx| {
        // Customise rendering of the JsonTree, and/or handle interactions.
        match ctx {
            RenderContext::Property(ctx) => {
                ctx.render_default(ui).context_menu(|ui| {
                    // Show a context menu when right clicking
                    // an array index or object key.
                });
            }
            RenderContext::BaseValue(ctx) => {
                // Show a button after non-recursive JSON values.
                ctx.render_default(ui);
                if ui.small_button("+").clicked() {
                    // ...
                }
            }
            RenderContext::ExpandableDelimiter(ctx) => {
                // Render array brackets and object braces as normal.
                ctx.render_default(ui);
            }
        };
    })
    .show(ui);

// Reset the expanded state of all arrays/objects to respect the `default_expand` setting.
response.reset_expanded(ui);

See demo.rs and run the examples for more detailed use cases, including:

  • Automatic expansion of arrays/objects and highlighting, based on search term matches.
  • Copying JSON paths and values to the clipboard.
  • A JSON editor UI.

Supported JSON Types

JsonTree can visualise any type that implements value::ToJsonTreeValue.

See the table of crate features below for provided implementations.

Feature/Dependency JSON Type Default
serde_json serde_json::Value Yes
simd_json simd_json::owned::Value No

If you wish to use a different JSON type, see the value module, and disable default features in your Cargo.toml if you do not need the serde_json dependency.

Run Examples

cargo run --example=demo

Dependencies

~5–11MB
~119K SLoC