Using jq to format JSON on the clipboard(chris48s.github.io) |
Using jq to format JSON on the clipboard(chris48s.github.io) |
tr '\n' ' ' | sed 's/\t/ /g; s/ */ /g'
But also I switched to xsel at one point, as xclip doesn't seem to deal as well with unicode. It could be xclip has been fixed since then, though.It’s great as it is included by default in RHEL/Fedora
> yq is a portable command-line YAML, JSON, XML, CSV, TOML, HCL and properties processor
function clipboard-format-json
# Inspired by https://chris48s.github.io/blogmarks/posts/2021/jsontidy/
if set -l formatted "$(wl-paste | jq '.')"
wl-copy $formatted
end
end
By saving it to .config/fish/functions/clipboard-format-json.fish, it should immediately workSo, copy text to clipboard, press a hotkey to popup the menu, and it'll offer options depending on the detected text. For example changing the clipboard contents to prettified (if it detects JSON, XML, HTML), or formatting a number back and forth (e.g. working with SSN's out of numerical DB entries when they prefer AAA-GG-SSSS).
The extra nice thing about jet is you can convert json into edn, then pipe it into an inline babashka repl where you can inspect the object with all the power of clojure. It is super duper nice for quickly looking through hunks (even huge hunks) of json. You can sum things up, filter through thousands of elements, generate a json schema with malli, whatever you want!
The j2p is pretty self-evident if you know any python, and the only trick to p2j was knowing `ast.literal_eval(input_str)`.
On mobile, but I believe for one of them on WSL is something like 'paste.exe'