logoalt Hacker News

Using jq to format JSON on the clipboard

36 pointsby stefanvdw1today at 12:35 PM11 commentsview on HN

Comments

lkbmtoday at 3:47 PM

I have this as a bash script and a some similar bash and python scripts for converting between python's print(my_dict) and json, or to run some python (mostly the dicts) through black.

The j2p is pretty self-evident if you know any python, and the only trick to p2j was knowing `ast.literal_eval(input_str)`.

show 1 reply
nullgeotoday at 3:55 PM

I like the version where it throws the error. That way I will realize I might not have copied the right JSON (or forgotten to copy)

netsharctoday at 3:15 PM

A universal tool (well, since I use Windows, a Windows tool) to modify the clipboard would be cool.

So, 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).

OskarStoday at 2:25 PM

Lovely little alias, but I much prefer fracjson[0] pretty printing to jq, so I might go with that instead!

[0]: https://github.com/j-brooke/FracturedJson

pletnestoday at 3:30 PM

Cool idea! I think it would look better as a function than an alias, but that doesn’t matter much.

dpflantoday at 1:48 PM

There is also: - xq for xml - yq for yaml

show 2 replies
mhalikosentoday at 2:18 PM

I didn't even know such a tool existed until Opus used it.

stefanvdw1today at 12:35 PM

Not mine, just very useful

jdbloodstonetoday at 4:06 PM

[dead]