wwaldner
Edit JSON in LiveBook
I am trying to figure out a way to load a file in Livebook and then allow editing parts of the data in editor. I want the Livebook to be able to perform subsequent actions on the data. This seems such a simple use case that I can’t believe I am having such a hard time figuring this out.
The basic issue I have is getting data a file/variable into a Kino. The only way I see doing this would be to create a smartcell that would introspect the variables in the livebook, and provide a custom JS editor that would allow editing the data. This is way too much work. I would be happy to just show the data in a JSON format so it can be edited and the allow other subsequent actions on the data.
The sample Livebook tutorials has a MD that gets me so close, but falls short of what I need. The sample allows showing an editor and assigning JSON to a variable in the Livebook. This is exactly what I need to do, however, I would like a fixed variable name and populate the editor with data read from a file. I don’t see a way to get data into the JSON editor from another variable or a file.
This can be 4 different sections/frames of the Livebook
- Load CSV file into variable

- Parse CSV and prepare a couple chunks of JSON

- Allow editing the JSON(perfer to use code editor, but could build Kino form)

- Perform actions on the JSON

# Untitled notebook
```elixir
Mix.install([
{:jason, "~> 1.4"},
{:kino, "~> 0.13.1"}
])
Load
var1 = %{name: "fred"} |> Jason.encode!()
Editing
# I want to be able to edit the JSON in code editor
# show me the editor with
Kino.Text.new(var1)
Actions
# OK, do some actions on var1
Most Liked
acalejos
I did something similar in Merquery.
It’s a SmartCell using a JS editor just like you said. It’s using CodeMirror, and even
has prettification for JSON using Prettier.
Check it out and maybe it’ll point you in the right direction.
It will also parse the JSON on the server side, and if it’s valid, decode it into a JSON map.







