json_source_on_stdout | jq . json_source_on_stdout | jq . pbpaste | jq . | pbcopy
Pretty sure this is one of my most frequent commands.1. Start Automator.
2. In the "Choose a type..." sheet, choose "Quick Action".
3. Set these:
Workflow recieves "current text" in "any application".
Input is "entire selection". [X] Output replaces text.
4. Add "Run shell script" and select your preferred shell. jq .
(Note that Automator is handling your stdin / stdout.)5. File / Save.
You can now find your workflow by command-clicking the document name in the window's titlebar. It should be in /Users/You/Library/Services
Now, fire up TextEdit, enter some JSON. Right-click, select Services and your service should be present. It's also in the TextEdit menu under Services.
cat input.json | python3 -m json.tool
For example, I wanted to write a simple expression to delete outputs from an ipython notebook.
{
"cells": [{
"stuff": "blah blah",
"outputs": ["crap", "to", "delete"]
}], "other stuff": "blah blah"
}
The simplest expression I could come up with was: merge(@, {
"cells": map(
&merge(@, {"outputs": `[]`}),
cells[]
)
})
And that's verbose because you're reconstructing the structure.In fairness, it's impressive that the language can express it at all, given it's a query language.
Maybe the real answer is to denote a subset of JMESPath that is guaranteed to return assignable nodes, that is only selects, slices, filters, etc. Then you run the query and perform assignments against those.
json_source_on_stdout | jq
If you give `jq` no arguments it acts like `jq .`