wwaldner

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

  1. Load CSV file into variable :white_check_mark:
  2. Parse CSV and prepare a couple chunks of JSON :white_check_mark:
  3. Allow editing the JSON(perfer to use code editor, but could build Kino form) :sos:
  4. Perform actions on the JSON :white_check_mark:
# 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

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.

Where Next?

Popular in Questions Top

pgiesin
This should be a simple problem but I just can’t seem to figure it out. I have a standalone Elixir app that won’t find the database. Dep...
New
ycv005
I have followed this StackOverflow post to install the specific version of Erlang. And When I am running mix ecto.setup then getting fol...
New
Werner
Hi, I’m using Ubuntu 18.04 and after updating to OTP-24.0 yesterday i have this warning when I run “mix local.hex”: 14:57:30.512 [warn] ...
New
SoCreat
i’m a new one to elixir which editor can i use vs code? or atom? Thanks! :smiley:
New
mgjohns61585
Could someone help me? I'm making my first elixir program, number guessing game. I can't figure out how to convert the user's guess from ...
New
electic
Hi, I am new to Elixir. I am trying to use the DateTime component to insert a date into MySQL however the there seems to be no way to fo...
New
chrisalley
ExUnit now has describe blocks which is a welcome addition coming from RSpec. In the docs, it states that nested hierarchies of describe ...
New
Qqwy
Original source of discussion: This topic on the Pragmatic Programmers' Functional Web Development with Elixir, OTP, and Phoenix forum. ...
New
romenigld
I am trying to run a deploy with docker and I successfully runned with this command: docker build -t romenigld/blog-prod . but when I t...
New
siddhant3030
Hi, I have to write a raw query for one of my project. But till now I have used ecto queries and don’t have much experience writing raw ...
New

Other popular topics Top

JorisKok
I have a server on AWS, and was running a load test using artillery. When looking at the Phoenix dashboard I see the Ports going to 100% ...
New
New
nsuchy
Hi. I’ve noticed that Windows Powershell has it’s own IEX command and you cannot access Elixir’s IEX due to the conflict. This isn’t a cr...
New
vertexbuffer
Hello, can anybody help here..? I have a list of players and I what to delete an element, but every for loop the list is reverting to ori...
New
lastday4you
I wanted to check elixir version in phoenix because i found that my elixir is 1.5 but when i use Enum.chunk_by it said the function is un...
New
myronmarston
The Elixir Typespec docs show the following syntax for keyword lists in typespecs: # ... | [key: type] # keyword lis...
New
ashish173
I am using Ecto timestamps with postgres, I can see the timestamps() use the :naive_dateime but for my use case I wanted to store the ti...
New
josevalim
Hi everyone, One of the features added to Elixir early on to help integration with Erlang code was the idea of overridable function defi...
New
romenigld
I am trying to run a deploy with docker and I successfully runned with this command: docker build -t romenigld/blog-prod . but when I t...
New
Nvim
Elixir appears to be a superior language to Python. I don’t see any advantage of Python over Elixir. Are there any?
New

We're in Beta

About us Mission Statement