# Format JSON from your clipboard with jq

Original title: Using jq to format JSON on the clipboard

> Hacker News story 49535324 · language: en · submitted 2026-09-02
> Web version: https://zeli.app/story/49535324
> About this feed: https://zeli.app/llms.txt · Agent guide: https://zeli.app/skill.md

▲ 60 · by [stefanvdw1](<https://news.ycombinator.com/user?id=stefanvdw1>) · 💬 19
[original](<https://chris48s.github.io/blogmarks/posts/2021/jsontidy/>) · [HN discussion](<https://news.ycombinator.com/item?id=49535324>)

## Summary

A practical tip for developers: use jq to pretty-print JSON copied to the clipboard. The article shows a macOS alias using pbcopy/pbpaste, then adapts it for Linux with xclip, adding error handling to avoid overwriting the clipboard if the content isn't valid JSON.

## Key quote

> I like this pretty-printing/formatting capability so much, I have an alias that formats JSON I've copied (in my OS "clipboard") & puts it back in my clipboard.

## HN discussion (19 comments)

### [1-more](<https://news.ycombinator.com/item?id=49540174>)

> I do a lot of this and `pbpaste | sed s/^    // | pbcopy` and things like that. It just fits my brain better. What's nice about raycast as a macOS pasteboard manager is that whatever you last selected via Cmd-Shift-V is the output of `pbpaste`. I'm not 100% sure how that is affected by copying images though.

### [bilkow](<https://news.ycombinator.com/item?id=49539314>)

> Loved it! I made this version for `fish` and `wl-clipboard`:
>
> 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 work

### [_flux](<https://news.ycombinator.com/item?id=49538466>)

> I use similar approach for fixing up clipboard contents with
>
> 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.

---

## Cite

- Page: https://zeli.app/story/49535324
- Date: 2026-09-02
- Source: chris48s.github.io (https://chris48s.github.io/blogmarks/posts/2021/jsontidy/)
- Hacker News: https://news.ycombinator.com/item?id=49535324

## Other languages

- zh: https://zeli.app/zh/story/49535324 · markdown: https://zeli.app/zh/story/49535324.md
- ja: https://zeli.app/ja/story/49535324 · markdown: https://zeli.app/ja/story/49535324.md
- ko: https://zeli.app/ko/story/49535324 · markdown: https://zeli.app/ko/story/49535324.md
- de: https://zeli.app/de/story/49535324 · markdown: https://zeli.app/de/story/49535324.md
- es: https://zeli.app/es/story/49535324 · markdown: https://zeli.app/es/story/49535324.md
- ru: https://zeli.app/ru/story/49535324 · markdown: https://zeli.app/ru/story/49535324.md
