GithubHelp home page GithubHelp logo

dmackdev / egui_json_tree Goto Github PK

View Code? Open in Web Editor NEW
46.0 1.0 3.0 728 KB

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

License: Apache License 2.0

Rust 99.76% Just 0.24%
eframe egui rust ui ui-components widget

egui_json_tree's Introduction

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.
    .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 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

egui_json_tree's People

Contributors

dmackdev avatar juancampa avatar vitorramos avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar

egui_json_tree's Issues

Auto expand all & Search

Is there a way to use defaultexpand:All and the searchfunctionality as well? I'd like the json tree to be fully expanded when the gui opens instead of collapsed, but im not sure if i can enable both

Editing the JSON tree

Hey, I've recently found this library, thank you for the reasonable design and nice maintenance.

As far as I understand, the displayed JSON tree is read-only. Do you have plans to enable editing the JSON tree? If not, do you maybe have any estimates about the magnitude of effort that implementation would require?

I think that support for changing field names and values or adding/removing array items or object fields could be really useful. With editing enabled, this library could be easily used as a generic UI for any serde::De/Serialize type without the need of any derive macros. I've seen egui_struct, enum2egui, egui_inspect and others but they are much more limited in possibilities and code quality.

Cache `LayoutJob` construction

node::render_key and node::render_value both construct LayoutJob for rendering.

These operations can be cached using egui cache.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.