Skip to content

JSON Editor

Now that we have covered some of the basics of a “hello world” and “counter” app, we are ready to build and manage something more involved.

In this tutorial, we will be creating an application that gives the user a simple interface to enter key-value pairs, which will be converted and printed to stdout in json. The purpose of this application will be to give the user an interface to create correct json, instead of having to worry about commas and brackets themselves.

Here’s a gif of what it will look like if you run this:



Go ahead and set up a new rust project with

Terminal window
cargo new ratatui-json-editor

and put the following in the Cargo.toml:

crossterm = "0.27.0"
ratatui = "0.26.3"
serde = { version = "1.0.203", features = ["derive"] }
serde_json = "1.0.117"

or the latest version of these libraries.


Now create two files inside of src/ so it looks like this:


This follows a common approach to small applications in ratatui, where we have a state file, a UI file, and the main file to tie it all together.