Bash JSON Viewer — jless & JQ_COLORS
मुफ़्त JSON Pretty Print को सीधे अपने ब्राउज़र में उपयोग करें — इंस्टॉलेशन की ज़रूरत नहीं।
JSON Pretty Print ऑनलाइन आज़माएं →जब आपको scripting के बजाय interactive exploration के लिए एक bash JSON viewer की जरूरत होती है, तो standard jq . pipe कम पड़ जाती है — output terminal के top पर scroll हो जाता है और 300-line API response में navigate करने का कोई तरीका नहीं बचता। यह guide terminal में JSON को interactively देखने के लिए specially built tools को cover करती है: jless (vim-key navigation के साथ collapsible tree), JQ_COLORS custom color themes, jq -C | less -R colorized paging, daily use के लिए shell aliases, और fx एक Node.js alternative के रूप में। Scripting, CI/CD, और validation workflows के लिए, companion Bash में JSON Format करें guide देखें। Zero-install browser viewer के लिए, JSON सौंदर्यीकरण tool instantly काम करता है। Examples Bash 5.x (macOS via Homebrew, Ubuntu 22.04+) पर test किए गए हैं और Bash 3.2+ (macOS system shell) के साथ compatible हैं।
- •
jless— terminal के लिए best interactive JSON viewer: collapsible tree, vim-keys, incremental search - •
jq -C . | less -R— jq के अलावा extra install के बिना colorized scrollable pager - •
JQ_COLORS— env variable जो हर JSON type के लिए jq का ANSI color scheme customize करता है - •
fx— mouse support और JavaScript filter expressions के साथ interactive Node.js JSON viewer - •
alias jv='jless'— एक-word command interactive viewing को muscle memory habit बनाता है
Interactive vs. Scripted JSON Viewing
JSON को jq . में pipe करना सही choice है जब आप छोटे payload के लिए formatted output चाहते हैं, या जब result किसी अन्य command में feed होता है। यह गलत choice है जब आपको 200-field API response कोexplore करना है — output terminal window से उड़ जाता है और आपके पास filter के साथ command दोबारा चलाए बिना navigate, sections collapse, या specific field खोजने का कोई तरीका नहीं बचता। Interactive JSON viewers उसी formatted, colorized output को एक persistent pager के अंदर render करते हैं जहां आप navigation control करते हैं। Data identical है; अंतर interface का है।
# jq . — output scrolls off screen for large responses curl -s https://api.github.com/users/torvalds | jq . # 300+ lines scroll past — you lose context immediately
# jless — opens an interactive pager, nothing scrolls off curl -s https://api.github.com/users/torvalds | jless # Full document visible, collapsible, searchable with j/k/h/l
jq को explicit filters और exit code handling के साथ उपयोग करें। Bash में JSON Format करें guide उन scripting patterns को cover करती है।jless — Interactive JSON Viewer
jless एक purpose-built terminal JSON viewer है। Plain jq pipe के विपरीत, यह document को एक persistent collapsible tree के रूप में render करता है: हर object और array को l और h से independently expand या collapse किया जा सकता है, navigation vim-style keys उपयोग करती है, और incremental search किसी भी key या value को instantly find करती है। यह input को incrementally stream करता है, इसलिए large files और API responses को size की परवाह किए बिना एक second से कम में खोलता है — जहां jq कुछ भी display करने से पहले पूरे document को buffer करता है। जब भी API response एक नज़र में scan करने के लिए बहुत बड़ा हो, मैं पहले tool के रूप में jless का उपयोग करती हूं।
Installation
# macOS brew install jless # Linux — prebuilt binary from GitHub Releases curl -sL https://github.com/PaulJuliusMartinez/jless/releases/latest/download/jless-x86_64-unknown-linux-gnu.tar.gz \ | tar xz sudo mv jless /usr/local/bin/ # Verify jless --version
Basic usage
# Open a local file — interactive tree viewer launches immediately jless api-response.json # Pipe any JSON stream directly into jless curl -s https://api.github.com/users/torvalds | jless # Open with all nodes collapsed to top level (useful starting point for large documents) jless --mode line api-response.json # Load a specific array element and view it in isolation jq '.[0]' deployments.json | jless
Practice में navigation और search
# Inside jless: # # j / ↓ move down # k / ↑ move up # l / → expand node (or Enter) # h / ← collapse node # H collapse current + all siblings → high-level overview # L expand everything recursively # # / start forward search — type a key name and press Enter # n / N next / previous search match # # g / gg jump to start # G jump to end # q quit
jless Keyboard Shortcuts Reference
jless खोलने के तुरंत बाद सभी shortcuts उपलब्ध हैं — कोई configuration की जरूरत नहीं। Navigation model जानबूझकर vim के समान है ताकि existing muscle memory transfer हो सके।
jq -C | less -R — Extra Tools के बिना Colorized Paging
अगर jless installed नहीं है और आपको JSON response का scrollable, colorized view चाहिए, jq -C . | less -R एक capable fallback है। -C flag ANSI color codes को force करता है यहाँ तक कि जब stdout एक pipe हो (normally jq उन्हें strip करता है), और -R less को उन codes को literal text के रूप में print करने के बजाय render करने के लिए कहता है। Result है एक fully colorized, scrollable document — jless की interactive tree structure के बिना। less के अंदर navigation arrow keys या vim-style j/k उपयोग करती है, और / less की built-in text search को trigger करती है।
# Basic colorized pager jq -C . response.json | less -R # From a curl response — -s prevents progress bar from corrupting the JSON stream curl -s https://api.github.com/repos/jqlang/jq | jq -C . | less -R # Sort keys for easier visual scanning, then page jq -CS . config.json | less -R # -C = force color, -S = sort keys (both flags combined) # Add an alias so you never have to type the full pipe again alias jqv='jq -C . | less -R' # Usage: cat response.json | jqv # or: curl -s https://api.example.com/status | jqv
jq -C | less -R less के display करने से पहले पूरे formatted output को buffer करता है। 200 MB file पर इसका मतलब है कई seconds का wait और significant memory consumption — plain jq . की same limitation। Large files के लिए, jless का उपयोग करें जो incrementally stream करता है।JQ_COLORS — Custom Color Themes
JQ_COLORS एक environment variable है जो jq के default ANSI color scheme को override करता है। यह इस fixed order में प्रत्येक JSON type के लिए एक के साथ, सात ANSI attribute;color codes की colon-separated string लेता है: null : false : true : numbers : strings : arrays : objects। प्रत्येक code attribute;color format में है जहाँ attribute 0 (normal), 1 (bold), 2 (dim), या 4 (underline) है, और color एक standard ANSI color number है (30–37 = standard, 90–97 = bright)।
# ANSI color reference for building JQ_COLORS: # Attributes: 0=normal 1=bold 2=dim 4=underline # Colors: 30=black 31=red 32=green 33=yellow # 34=blue 35=magenta 36=cyan 37=white # Bright: 90=bright-black 91=bright-red 92=bright-green 93=bright-yellow # 94=bright-blue 95=bright-magenta 96=bright-cyan 97=bright-white # # Order: null : false : true : numbers : strings : arrays : objects # High-contrast theme for dark terminals (recommended) export JQ_COLORS="1;30:0;91:0;92:0;93:0;32:1;96:1;96" # null=dim-gray, false=bright-red, true=bright-green, # numbers=bright-yellow, strings=green, arrays=bold-cyan, objects=bold-cyan # Solarized-style theme export JQ_COLORS="2;37:0;35:0;35:0;36:0;33:1;34:1;34" # null=dim-white, false=magenta, true=magenta, # numbers=cyan, strings=yellow, arrays=bold-blue, objects=bold-blue # Minimal (bold keys only, everything else plain) export JQ_COLORS="0;90:0;39:0;39:0;39:0;39:1;39:1;39"
# Add your chosen theme to ~/.bashrc or ~/.zshrc so it applies to every jq call
echo 'export JQ_COLORS="1;30:0;91:0;92:0;93:0;32:1;96:1;96"' >> ~/.bashrc
source ~/.bashrc
# Test the theme
echo '{"active":true,"errors":null,"count":42,"tags":["api","v2"],"meta":{"version":"1.0"}}' | jq .JQ_COLORS में exactly सात colon-separated values होनी चाहिए। अगर string में कम segments हैं, jq बिना किसी error message के silently अपने built-in defaults पर fall back कर देता है — जिससे misconfiguration diagnose करना मुश्किल हो जाता है। Shell profile में add करने से पहले हमेशा एक short JSON payload पर new color string test करें।Daily JSON Viewing के लिए Shell Aliases
Interactive JSON viewing के commands default में verbose हैं। ~/.bashrc या ~/.zshrc में aliases का एक छोटा set jless और colorized paging को single-word commands बनाता है जो किसी भी workflow में naturally integrate होते हैं। नीचे के aliases compose होते हैं — jv और jvp दोनों piped input या first argument के रूप में filename accept करते हैं।
# Add to ~/.bashrc or ~/.zshrc
# jv — interactive viewer (jless if available, colorized pager fallback)
jv() {
if command -v jless &>/dev/null; then
jless "$@"
else
jq -C . "$@" | less -R
fi
}
# jvp — view with keys sorted alphabetically (useful for comparing responses)
alias jvp='jq -CS . | less -R'
# jvc — view from clipboard (macOS)
alias jvc='pbpaste | jless'
# jvf — view and filter: jvf '.users[0]' response.json
jvf() {
local filter="$1"; shift
jq -C "$filter" "$@" | less -R
}
# Reload without restarting terminal
source ~/.bashrc# Usage examples after adding aliases above # View any file or piped response jv deployment-config.json curl -s https://api.github.com/users/torvalds | jv # View sorted (easy to scan alphabetically) cat feature-flags.json | jvp # Drill into a sub-document interactively jvf '.database' infra/app-config.json jvf '.users[] | select(.role == "admin")' users.json
bat — Syntax-Highlighted JSON File Viewing
bat, cat का एक replacement है जिसमें syntax highlighting, line numbers, और एक built-in pager है। Disk पर JSON files के लिए यह full text editor खोले बिना एक clean, editor-style reading experience प्रदान करता है। jless के विपरीत, bat file को static text के रूप में render करता है — कोई collapse नहीं, कोई search नहीं, scrolling से परे कोई navigation नहीं। इसकी strength medium-sized static files (configs, fixtures, test payloads) के लिए visual clarity है जहाँ आप syntax color और line numbers चाहते हैं लेकिन interactive tree navigation की जरूरत नहीं।
# macOS brew install bat # Debian / Ubuntu (binary may be named batcat) apt-get install -y bat # alias bat=batcat # add to ~/.bashrc if needed on Ubuntu # View a JSON file with syntax highlighting and line numbers bat config/feature-flags.json # Disable pager — print directly to terminal (useful in scripts) bat --paging=never api-response.json # Combine with jq: format with jq, view with bat (preserves bat's JSON highlighting) jq '.' response.json | bat --language=json --paging=never
bat का उपयोग करें जहाँ line numbers matter करते हैं (जैसे जब test failure किसी fixture file के line 47 को reference करती है)। curl से API responses और dynamic JSON के लिए, jless तेज़ी से open होता है और navigate करना अधिक practical है। अगर browser में देखना है और colleague के साथ share करना है, तो directly JSON सौंदर्यीकरण tool में paste करें — terminal की जरूरत नहीं।fx — Interactive Node.js JSON Explorer
fx Node.js पर built एक interactive JSON viewer है। इसका interface jless के समान है — collapsible tree, keyboard navigation, search — लेकिन यह दो features add करता है जो jless में नहीं हैं: mouse support (expand/collapse nodes के लिए click करें) और real time में document filter करने के लिए bottom bar में JavaScript expression type करने की ability। Node.js already run कर रही teams के लिए, fx एक natural fit है और अलग binary की जरूरत नहीं। Node के बिना pure terminal environments के लिए, jless leaner choice है।
# Install globally via npm npm install -g fx # Or run without installing (npx caches the package) curl -s https://api.github.com/users/torvalds | npx fx # Basic interactive use fx api-response.json curl -s https://api.github.com/repos/jqlang/jq | fx # In fx: arrow keys navigate, Enter expands/collapses, / searches # Bottom bar accepts JavaScript expressions for live filtering: # .name → show only the "name" field # .repos.slice(0,5) → first 5 repos
# fx also works as a non-interactive formatter (like jq . but with JS syntax)
# Pass a JavaScript expression as argument — no interactive mode
echo '{"users":[{"id":1,"name":"Sarah Chen"},{"id":2,"name":"Marcus Osei"}]}' \
| fx '.users[0].name'
# Sarah Chen
# Chain with map for array transformations
cat deployments.json | fx '.items.map(d => ({id: d.deploy_id, status: d.state}))'Common Mistakes
ये चार गलतियाँ बार-बार आती हैं जब developers terminal JSON viewers का पहली बार उपयोग शुरू करते हैं — एक बार समझने के बाद प्रत्येक का एक clear fix है।
समस्या: jq . सारा output एक साथ stdout पर dump करता है। Terminal height से लंबे responses के लिए, last screenful से ऊपर की सब कुछ gone — आप beginning में वापस scroll नहीं कर सकते या filter के साथ command rerun किए बिना specific field पर navigate नहीं कर सकते।
समाधान: Interactive navigation के लिए jless में pipe करें, या fallback के रूप में jq -C . | less -R उपयोग करें। दोनों size की परवाह किए बिना full document accessible रखते हैं।
# 300-line API response — top 280 lines immediately scroll off curl -s https://api.github.com/users/torvalds | jq . # Only the bottom of the output is visible — cannot navigate back
# Full document stays accessible in jless — nothing is lost curl -s https://api.github.com/users/torvalds | jless # j/k to scroll, h/l to collapse/expand, / to search
समस्या: JQ_COLORS को exactly सात colon-separated values की जरूरत है। अगर string में छह या आठ values हैं, jq silently पूरे variable को ignore करता है और compiled-in defaults पर fall back करता है — कोई warning नहीं, कोई error नहीं, बस गलत colors।
समाधान: Colons count करें: एक valid JQ_COLORS string में exactly छह colons और सात values होती हैं। Variable को echo करें और count करने के लिए tr में pipe करें।
# Only 6 values — jq silently uses defaults, no indication of why
export JQ_COLORS="1;30:0;91:0;92:0;93:0;32:1;96"
echo '{"ok":true}' | jq . # colors unchanged — no error shown# Exactly 7 values — 6 colons export JQ_COLORS="1;30:0;91:0;92:0;93:0;32:1;96:1;96" # Verify the count before adding to shell profile echo "$JQ_COLORS" | tr -cd ':' | wc -c # must output 6
समस्या: jless और fx अपना interactive interface stdout पर नहीं, terminal (TTY) पर render करते हैं। उन्हें grep, tee, या किसी अन्य command में pipe करने से garbled ANSI escape codes या empty output मिलता है — viewer का interactive output दूसरे programs द्वारा consume किए जाने के लिए designed नहीं है।
समाधान: Data programmatically extract करने के लिए explicit filter के साथ jq उपयोग करें। jless और fx को केवल pipeline में final step के रूप में उपयोग करें जब कोई human output पढ़ रहा हो।
# jless output is for human eyes — piping it produces garbage jless response.json | grep "request_id" # Output: ANSI escape codes and cursor sequences, not clean text
# Use jq for programmatic extraction — clean, composable jq -r '.request_id' response.json | grep "req_" # Use jless only as the terminal endpoint — nothing after it jless response.json
समस्या: -C ANSI color codes को output stream में force करता है। जब वह stream directly एक terminal पर print होती है जो raw mode में नहीं है — या किसी ऐसे tool में pipe होती है जो ANSI interpret नहीं करता — escape sequences ^[[1;34m जैसे literal characters के रूप में दिखते हैं जो output को clutter करते हैं।
समाधान: jq -C को हमेशा less -R के साथ pair करें। -R flag less को raw-input mode में डालता है, उसे ANSI sequences को text के रूप में print करने के बजाय colors के रूप में render करने के लिए कहता है।
# -C without -R: escape sequences print as raw text jq -C . response.json | less # Output: ^[[1;34m"status"^[[0m: ^[[0;32m"ok"^[[0m ...
# -C with -R: ANSI codes are rendered as actual colors jq -C . response.json | less -R # Output: colorized JSON, clean and readable
jless vs jq vs bat vs fx — Interactive Viewer Comparison
चारों tools colorized JSON render करते हैं, लेकिन उनकी interactive capabilities significantly differ करती हैं। Choose करें based पर कि आपको collapsible navigation, search, या mouse support चाहिए — और क्या Node.js already आपके environment में है।
अधिकांश situations के लिए: jless एक बार install करें और default interactive viewer के रूप में उपयोग करें। उन environments के लिए jq -C . | less -R को fallback के रूप में रखें जहाँ additional binaries install नहीं कर सकते। fx add करें अगर आपकी team Node.js-first है और mouse navigation या live JavaScript filtering को value देती है।
Frequently Asked Questions
Terminal में JSON file के अंदर किसी specific key को कैसे खोजें?
jless में / दबाएं incremental search prompt खोलने के लिए, key का नाम टाइप करें, और Enter दबाएं। matches के बीच आगे जाने के लिए n और पीछे जाने के लिए N का उपयोग करें। Search default में case-sensitive होती है। jq -C | less -R में / less की built-in search को trigger करता है जो ANSI color codes सहित raw text को match करता है — structured JSON के लिए jless search अधिक reliable है।
# Open file in jless, then press / to search jless api-response.json # In jless: type / → "request_id" → Enter → n for next match # jq alternative: extract and print all matching keys to stdout jq '.. | objects | with_entries(select(.key == "request_id"))' api-response.json
Keyboard shortcuts से deeply nested JSON structure में navigate कैसे करें?
jless, vim navigation को mirror करता है: j/k ऊपर/नीचे के लिए, h एक node को collapse करने के लिए, l उसे expand करने के लिए। H दबाएं वर्तमान node और उसके सभी siblings को एक साथ collapse करने के लिए — किसी specific branch में जाने से पहले high-level overview पाने के लिए उपयोगी। L सब कुछ recursively expand करता है। एक बार सब कुछ top level पर collapse करने के बाद, l से केवल उस path को expand करें जो आप चाहते हैं।
# Open the response in jless curl -s https://api.github.com/repos/jqlang/jq | jless # In jless: # H → collapse all top-level keys # j/k → navigate to the key you want # l → expand only that branch # gg → return to root # G → jump to last element
Dark terminal पर jq color output को अधिक readable कैसे बनाएं?
प्रत्येक JSON type के लिए ANSI attribute;color codes के साथ JQ_COLORS environment variable set करें। सात positions क्रम में हैं: null, false, true, numbers, strings, arrays, objects। हर jq call पर apply करने के लिए export को ~/.bashrc या ~/.zshrc में डालें। Bold bright colors dark backgrounds पर सबसे अच्छा काम करते हैं।
# High-contrast theme for dark terminals — add to ~/.bashrc or ~/.zshrc
export JQ_COLORS="1;30:0;91:0;92:0;93:0;32:1;96:1;96"
# null=gray, false=bright-red, true=bright-green,
# numbers=bright-yellow, strings=green, arrays/objects=bright-cyan
# Test immediately without reloading shell
echo '{"active":true,"errors":0,"tags":["api","v2"]}' | jq .JSON देखने के लिए jless और jq . में क्या अंतर है?
jq . सारा output एक साथ stdout पर dump करता है। terminal height से लंबे responses के लिए, last screenful से ऊपर की सब कुछ चली जाती है — आप शुरुआत में वापस scroll नहीं कर सकते या filter के साथ command दोबारा चलाए बिना specific field पर navigate नहीं कर सकते। jless पूरे document को एक persistent pager में render करता है जहां आप scroll, search, nodes collapse कर सकते हैं और keyboard shortcuts से navigate कर सकते हैं बिना context खोए। छोटे payload पर नज़र डालनी हो तो jq . उपयोग करें; explore करना हो तो jless उपयोग करें।
# Small payload — jq . is fine
echo '{"status":"ok","version":"2.4.1"}' | jq .
# Large or nested response — jless is better
curl -s https://api.github.com/repos/jqlang/jq | jless
# → interactive tree, no output scrolled off screenTerminal में curl response से JSON को interactively कैसे देखें?
curl को directly jless में pipe करें। curl के progress bar को output में आने से रोकने के लिए हमेशा -s (silent) शामिल करें। jless पूरे response को collapsible tree के रूप में render करके interactive viewer खोलेगा। अगर jless installed नहीं है, तो jq -C . | less -R fallback के रूप में colorized pager देता है।
# Interactive exploration with jless curl -s https://api.github.com/users/torvalds | jless # Colorized pager fallback (no collapse, but still scrollable with color) curl -s https://api.github.com/users/torvalds | jq -C . | less -R
क्या मैं terminal में multiple JSON files को side by side देख सकता हूं?
jless एक बार में एक file खोलता है। Side-by-side comparison के लिए terminal multiplexer उपयोग करें: tmux split-window -h एक vertical split खोलता है, फिर प्रत्येक pane में अलग file के साथ jless चलाएं। वैकल्पिक रूप से, browser-based JSON Diff tool उपयोग करें अगर आपको दो documents को structurally compare करना है।
# tmux side-by-side: split horizontally, then run jless in each pane tmux split-window -h # Left pane: jless response-v1.json # Right pane: jless response-v2.json # Or use diff on jq-normalized output for a text diff diff <(jq -S . response-v1.json) <(jq -S . response-v2.json)
Related Tools
JSON सौंदर्यीकरण tool आपको वही collapsible, colorized view देता है जैसा jless — directly browser में, बिना installation और बिना terminal के।
Cora is a platform engineer who builds developer tooling and internal platforms, using Bash as the glue that connects components written in different languages and runtimes. She writes about cross-platform shell scripting, Bash utility functions, environment management, configuration templating, and the practical shell techniques that platform engineers use to build self-service tooling for development teams.
Nadia is a site reliability engineer who lives in the terminal. She writes Bash scripts that process logs, transform data, and orchestrate infrastructure across fleets of servers. She is a heavy user of jq, awk, and sed and writes about shell one-liners, text processing pipelines, data serialisation from the command line, and the practical Bash patterns that SREs reach for when speed matters more than elegance.