JED, the loyal json successor to SED

Camilo MATAJIRA Avatar

Lately, I have felt dissatisfied with jq for manipulating json in the command line and in scripts.
The personal reason, is that I like investing in tools that have withstood the test of time and I like learning them well.

One example of these tools is vim. Learning vim has had a great payoff, and part of its charm is that, if I grow tired of it I can still transfer my knowledge of the vim key bindings to other tools or editors. I could move to Neovim, or if I’m more interested in writing text, I could use the key bindings in Obsidian. I have seen plugins for vim in VS Code, JetBrains, etcetera. And having studied vim, understanding a tool like grep is natural g/re/p (I do know that g/re/p comes from ex).

My point is that learning vim has been a safe bet with high return. The same is true for sed and awk. Yet, here is jq, that claims to be a “jq is like sed for JSON data – you can use it to slice and filter and map and transform structured data with the same ease that sed, awk, grep and friends let you play with text.” But jq does not resemble anything of sed, awk or grep. I can’t transfer my knowledge of sed, awk or grep to jq.

That why, I started working on JED (json sed). My objective is to create a json parsing tools that feels like home for sed power users. And if I do it correctly, the benefits would be evident: not because of the tools itself, but because sed is great.

What I have in mind is something like this, let’s start with a simple json:

{
"sha": "0eb3",
"node_id": "OAE3WVd",
"commit": {
  "author": {
    "name": "Camilo MATAJIRA",
    "email": "ca.matajira966@gmail.com",
    "date": "2025-11-27T09:44:45Z"
  },
  "committer": {
    "name": "Camilo MATAJIRA",
    "email": "fake_email@gmail.com",
    "date": "2025-11-27T09:44:45Z"
  },

Let say that I want to change “Camilo MATAJIRA” to “Camilo A. MATAJIRA”.
I could do that very easily with sed:

sed 's/Camilo MATAJIRA/Camilo A. MATAJIRA/g' file.json

Yet, what if I want to do this only on the “author” section and not in the committer?
With sed, I could do something like this:

sed '/"author"/,/}\,/ s/Camilo MATAJIRA/Camilo A. MATAJIRA/g' file.json

I would profit from sed’s range feature, that allows me to specify a range of lines where the substitution would take place. It will work, but we start having the flavor that sed could profit from understanding the hierarchical nature of json.

In jed I could do:

jed '/author/ s/Camilo MATAJIRA/Camilo A. MATAJIRA/g' file.json

This would read like “wherever you find a key, at any level of the tree hierarchy that satisfies the regex /author/, perform the following substitution.”

This could also be written like:

jed '/commit/./author/ s/Camilo MATAJIRA/Camilo A. MATAJIRA/g' file.json

This would read “wherever you find a succession of keys at any level of the json, the first one should satisfy the regex /commit/, and the next one (the child) satisfies /author/, perform the following substitution there.”

jed '/commit/./author/./name/ s/Camilo MATAJIRA/Camilo A. MATAJIRA/g' file.json

This one would read like the previous one but adding the condition of the last key being “name”.

It is important to note, that I said these all are regular expressions.

jed '/^comm.*/./aut.*/ s/Camilo MATAJIRA/Camilo A. MATAJIRA/g' file.json

This would work the same, but is very pleasant to be able to work with regexes, and not be tight to providing the exact succession of keys.

Now, let’s say that I would like to change the key “name” to “author_name”, in other words I would like commit.author.name → commit.author.author_name.
I could do it in many ways:

jed '/author/ S/name/author_name/g' file.json

First check that I use “S” instead of “s”, because we are substituting a key, not a value. This is a way of differentiation when the actions should operate on keys rather than values.
And this reads “where you find a key, at any level of the json, that satisfies /author/, perform the substitution of key name to author_name there.”

But how about I want the values to be part of the regex conditions?
Let’s say that I want to change the key “email” to “committer_email” but only where the value of email is “fake_email@gmail.com”. Again, many ways to do it, but one way is:

jed ':/fake_email@gmail.com/ S/email/commiter_mail/g' file.json

See the “:” at the beginning? This indicates that the regex expression is applying to the values, not to the keys.
Other equivalent way to do it:

jed '/.*/:/fake_email@gmail.com/ S/email/commiter_mail/g' file.json
jed '/.*/./.*/:/fake_email@gmail.com/ S/email/commiter_mail/g' file.json
jed '/.*/./.*/./.*/:/fake_email@gmail.com/ S/email/commiter_mail/g' file.json

Similar operations would apply for deletion (d and D), appending (a and A), inserting (i and I), and changing (c and C).

In conclusion, this is the project that I would like to create. I started working already on the DSL, I hope that it will be useful to you too.

Tagged in :

Camilo MATAJIRA Avatar

One response to “JED, the loyal json successor to SED”

  1. […] of sed but specialized in JSON data manipulation.I have written about this project before: https://camilo.matajira.com/?p=635 […]