Bash JSON Viewer — jless & JQ_COLORS
ใช้ จัดรูปแบบ JSON สวยงาม ฟรีโดยตรงในเบราว์เซอร์ของคุณ — ไม่ต้องติดตั้ง
ลอง จัดรูปแบบ JSON สวยงาม ออนไลน์ →เมื่อคุณต้องการ bash JSON viewer สำหรับการสำรวจแบบ interactive แทนการเขียน script pipe มาตรฐาน jq . ไม่เพียงพอ — output เลื่อนผ่านด้านบนของ terminal และคุณไม่มีวิธีนำทางกลับผ่าน API response 300 บรรทัด คู่มือนี้ครอบคลุมเครื่องมือที่สร้างมาเพื่อ ดู JSON แบบ interactive ใน terminal โดยเฉพาะ: jless (แผนผัง ที่ยุบได้พร้อมการนำทางด้วยปุ่ม vim), JQ_COLORS ธีม สีที่กำหนดเอง, jq -C | less -R การ แบ่งหน้าแบบมีสี, shell aliases สำหรับการใช้งานประจำวัน, และ fx เป็น ทางเลือก Node.js สำหรับ scripting, CI/CD และ workflows การตรวจสอบ ดูคู่มือ จัดรูปแบบ JSON ใน Bash ที่เป็นคู่กัน สำหรับ browser viewer ที่ไม่ต้องติดตั้ง เครื่องมือ จัดรูปแบบ JSON สวยงาม ทำงานได้ทันที ตัวอย่างทดสอบบน Bash 5.x (macOS ผ่าน Homebrew, Ubuntu 22.04+) และเข้ากันได้กับ Bash 3.2+ (macOS system shell)
- •
jless— JSON viewer แบบ interactive ที่ดีที่สุดสำหรับ terminal: แผนผังที่ยุบได้, vim-keys, incremental search - •
jq -C . | less -R— pager มีสีที่เลื่อนได้โดยไม่ต้องติดตั้งเพิ่มนอกจาก jq - •
JQ_COLORS— ตัวแปร environment ที่ปรับแต่ง ANSI color scheme ของ jq สำหรับแต่ละประเภท JSON - •
fx— JSON viewer Node.js แบบ interactive พร้อม mouse support และ JavaScript filter expressions - •
alias jv='jless'— คำสั่งคำเดียวทำให้การดูแบบ interactive เป็นนิสัยอัตโนมัติ
การดู JSON แบบ Interactive เทียบกับแบบ Script
การ pipe JSON ไปยัง jq . เป็น ตัวเลือกที่ถูกต้องเมื่อคุณต้องการ output ที่มีรูปแบบสำหรับ payload ขนาดเล็ก หรือเมื่อ ผลลัพธ์ถูกส่งต่อไปยังคำสั่งอื่น เป็นตัวเลือกที่ผิดเมื่อคุณต้องการ สำรวจ API response 200 field — output บินผ่านหน้าต่าง terminal และไม่มีวิธีนำทาง ยุบส่วน หรือค้นหา field เฉพาะโดยไม่รันคำสั่งซ้ำด้วย filter JSON viewers แบบ interactive render output ที่มีรูปแบบและสีเดียวกันภายใน pager แบบถาวรที่คุณควบคุมการนำทาง ข้อมูลเหมือนกันทุกอย่าง ความแตกต่างคือ 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 พร้อม filters ที่ชัดเจนและการจัดการ exit code คู่มือ จัดรูปแบบ JSON ใน Bash ครอบคลุม scripting patterns เหล่านั้นjless — JSON Viewer แบบ Interactive
jless เป็น terminal JSON viewer ที่สร้างมาเพื่อวัตถุประสงค์นี้โดยเฉพาะ ต่างจาก jq pipe ธรรมดา มัน render เอกสารเป็นแผนผังที่ยุบได้แบบถาวร: ทุก object และ array สามารถขยายหรือยุบได้ อย่างอิสระด้วย l และ h, การนำทางใช้ปุ่ม vim-style, และ incremental search ค้นหา key หรือค่าใดก็ได้ทันที มัน stream input แบบ incremental ดังนั้นจึงเปิดไฟล์ขนาดใหญ่และ API responses ใน เวลาไม่ถึงหนึ่งวินาทีโดยไม่คำนึงถึงขนาด — ซึ่ง jq จะ buffer เอกสารทั้งหมดก่อนแสดง อะไรก็ตาม ฉันเลือกใช้ jless เป็นเครื่องมือแรกเสมอเมื่อ API response ใหญ่เกินกว่า จะสแกนได้ในครั้งเดียว
การติดตั้ง
# 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
การใช้งานพื้นฐาน
# 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
การนำทางและการค้นหาในทางปฏิบัติ
# 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
ปุ่มลัดทั้งหมดพร้อมใช้งานทันทีหลังจากเปิด jless — ไม่ต้องตั้งค่า รูปแบบการนำทางตั้งใจให้เหมือนกับ vim เพื่อให้ความจำแบบกล้ามเนื้อที่มีอยู่แล้วสามารถถ่ายโอนได้
jq -C | less -R — การแบ่งหน้าแบบมีสีโดยไม่ต้องใช้เครื่องมือเพิ่มเติม
หาก jless ไม่ได้ติดตั้งและคุณต้องการดู JSON response แบบเลื่อนได้และมีสี, jq -C . | less -R เป็น fallback ที่มีความสามารถ Flag -C บังคับ ANSI color codes แม้เมื่อ stdout เป็น pipe (ปกติ jq จะลบออก) และ -R บอก less ให้ render codes เหล่านั้นแทนที่จะพิมพ์เป็นข้อความตัวอักษร ผลลัพธ์คือเอกสารที่ มีสีครบถ้วนและเลื่อนได้ — โดยไม่มีโครงสร้างแผนผัง interactive ของ jless การนำทาง ภายใน less ใช้ปุ่มลูกศรหรือ vim-style j/k, และ / เปิดใช้ การค้นหาข้อความในตัวของ less
# 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 buffer output ที่จัดรูปแบบแล้วทั้งหมด ก่อนที่ less จะแสดงได้ บนไฟล์ขนาด 200 MB หมายความว่าต้องรอหลายวินาทีและใช้หน่วยความจำ จำนวนมาก — ข้อจำกัดเดียวกับ jq . ธรรมดา สำหรับไฟล์ขนาดใหญ่ ใช้ jless แทนซึ่ง stream แบบ incrementalJQ_COLORS — ธีมสีที่กำหนดเอง
JQ_COLORS เป็น ตัวแปร environment ที่ override ANSI color scheme ค่าเริ่มต้นของ jq มันรับ string ที่ คั่นด้วยโคลอนของ ANSI attribute;color codes เจ็ดตัว หนึ่งตัวต่อประเภท JSON ตามลำดับ คงที่นี้: null : false : true : ตัวเลข : strings : arrays : objectsแต่ละ code อยู่ในรูปแบบ attribute;color โดยที่ attribute คือ 0 (ปกติ), 1 (ตัวหนา), 2 (จาง), หรือ 4 (ขีดเส้นใต้), และ color คือหมายเลขสี ANSI มาตรฐาน (30–37 = มาตรฐาน, 90–97 = สด)
# 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 ต้องมีค่าที่คั่นด้วยโคลอนเจ็ดค่าพอดี หาก string มี segments น้อยกว่า jq จะกลับไปใช้ค่าเริ่มต้นในตัวโดยไม่มีข้อความแสดง ข้อผิดพลาด — ทำให้วินิจฉัยการกำหนดค่าผิดพลาดได้ยาก ทดสอบ color string ใหม่กับ JSON payload สั้นๆ เสมอก่อนเพิ่มลงใน shell profileShell Aliases สำหรับการดู JSON ประจำวัน
คำสั่งสำหรับการดู JSON แบบ interactive มักจะยาวโดยค่าเริ่มต้น ชุด aliases เล็กๆ ใน ~/.bashrc หรือ ~/.zshrc ทำให้ jless และการแบ่งหน้าแบบมีสีเป็นคำสั่งคำเดียวที่รวมเข้ากับ workflow ใดก็ได้อย่าง เป็นธรรมชาติ aliases ด้านล่างรวมกันได้ — jv และ jvp ทั้งคู่ รับ piped input หรือชื่อไฟล์เป็น argument แรก
# 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 — การดูไฟล์ JSON พร้อม Syntax Highlighting
bat เป็น ตัวแทนของ cat พร้อม syntax highlighting, หมายเลขบรรทัด และ pager ในตัว สำหรับไฟล์ JSON บนดิสก์ มันให้ ประสบการณ์การอ่านที่สะอาดแบบ editor โดยไม่ต้องเปิด text editor เต็มรูปแบบ ต่างจาก jless, bat render ไฟล์เป็นข้อความคงที่ — ไม่มียุบ ไม่มีค้นหา ไม่มีการนำทางนอกจาก การเลื่อน จุดแข็งคือความชัดเจนทางภาพสำหรับไฟล์คงที่ขนาดกลาง (configs, fixtures, test payloads) ที่คุณต้องการสีตามไวยากรณ์และหมายเลขบรรทัดแต่ไม่ต้องการการนำทาง แผนผัง interactive
# 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 สำหรับอ่านไฟล์ config คงที่และ test fixtures ที่หมายเลขบรรทัดสำคัญ (เช่น เมื่อ test failure อ้างอิงบรรทัดที่ 47 ของไฟล์ fixture) สำหรับ API responses และ JSON แบบ dynamic จาก curl, jless เปิดได้เร็วกว่าและนำทาง ได้ง่ายกว่า หากต้องดูในเบราว์เซอร์และแบ่งปันกับเพื่อนร่วมงาน วางโดยตรงในเครื่องมือ จัดรูปแบบ JSON สวยงาม — ไม่ต้องใช้ terminalfx — JSON Explorer แบบ Interactive บน Node.js
fx เป็น JSON viewer แบบ interactive ที่สร้างบน Node.js Interface คล้ายกับ jless — แผนผังที่ ยุบได้, การนำทางด้วยแป้นพิมพ์, ค้นหา — แต่เพิ่มสองฟีเจอร์ที่ jless ขาด: รองรับ เมาส์ (คลิกเพื่อขยาย/ยุบ nodes) และความสามารถในการพิมพ์ JavaScript expression ใน bar ด้านล่างเพื่อกรองเอกสารแบบ real time สำหรับทีมที่รัน Node.js อยู่แล้ว fx เป็น ตัวเลือกที่เหมาะสมและไม่ต้องใช้ binary แยก สำหรับ pure terminal environments ที่ไม่มี Node, jless เป็นตัวเลือกที่เบากว่า
# 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}))'ข้อผิดพลาดที่พบบ่อย
ข้อผิดพลาดสี่ข้อนี้เกิดขึ้นซ้ำๆ เมื่อ developers เริ่มใช้ terminal JSON viewers เป็นครั้งแรก — แต่ละข้อมีวิธีแก้ที่ชัดเจนเมื่อเข้าใจสาเหตุ
ปัญหา: jq . ส่ง output ทั้งหมดไปยัง stdout ในครั้งเดียว สำหรับ responses ที่ยาวกว่าความสูงของ terminal ทุกอย่างที่อยู่เหนือ screenful สุดท้ายจะหายไป — คุณไม่สามารถเลื่อนกลับไปยังจุดเริ่มต้นหรือนำทางไปยัง field เฉพาะโดยไม่รันคำสั่งซ้ำด้วย filter
วิธีแก้: Pipe ไปยัง jless สำหรับการนำทางแบบ interactive หรือใช้ jq -C . | less -R เป็น fallback ทั้งคู่รักษาเอกสารทั้งหมดให้เข้าถึงได้โดยไม่คำนึงถึงขนาด
# 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 ต้องการค่าที่คั่นด้วยโคลอนเจ็ดค่าพอดี หาก string มีหกหรือแปดค่า jq จะเพิกเฉยต่อตัวแปรทั้งหมดอย่างเงียบๆ และกลับไปใช้ค่าเริ่มต้นที่คอมไพล์ไว้ — ไม่มีคำเตือน ไม่มีข้อผิดพลาด แค่สีที่ผิด
วิธีแก้: นับโคลอน: JQ_COLORS string ที่ถูกต้องมีโคลอนพอดีหกตัวและเจ็ดค่า Echo ตัวแปรและ pipe ไปยัง tr เพื่อนับ
# 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 render interface แบบ interactive ไปยัง terminal (TTY) ไม่ใช่ stdout การ pipe ไปยัง grep, tee หรือคำสั่งอื่นใดจะสร้าง ANSI escape codes ที่วุ่นวายหรือ output ว่าง — output interactive ของ viewer ไม่ได้ออกแบบมาเพื่อให้โปรแกรมอื่นใช้
วิธีแก้: ใช้ jq พร้อม filter ที่ชัดเจนเพื่อดึงข้อมูลแบบ programmatic ใช้ jless และ fx เฉพาะเป็นขั้นตอนสุดท้ายใน pipeline เมื่อมนุษย์กำลังอ่าน 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 เมื่อ stream นั้นถูกพิมพ์โดยตรงไปยัง terminal ที่ไม่ได้อยู่ใน raw mode — หรือ pipe ไปยังเครื่องมือที่ไม่ interpret ANSI — escape sequences จะปรากฏเป็นตัวอักษรเช่น ^[[1;34m ที่ทำให้ output ยุ่งเหยิง
วิธีแก้: จับคู่ jq -C กับ less -R เสมอ Flag -R วาง less ในโหมด raw-input บอกให้ render ANSI sequences เป็นสีแทนที่จะพิมพ์เป็นข้อความ
# -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 Viewers
เครื่องมือทั้งสี่ render JSON แบบมีสี แต่ความสามารถ interactive แตกต่างกันอย่างมีนัยสำคัญ เลือกตามว่าคุณต้องการการนำทางที่ยุบได้ การค้นหา หรือ mouse support — และว่า Node.js อยู่ใน environment ของคุณแล้วหรือไม่
สำหรับสถานการณ์ส่วนใหญ่: ติดตั้ง jless ครั้งเดียวและใช้เป็น interactive viewer ค่าเริ่มต้น เก็บ jq -C . | less -R เป็น fallback สำหรับ environments ที่ไม่สามารถติดตั้ง binaries เพิ่มเติม เพิ่ม fx หากทีม ของคุณเน้น Node.js และให้ความสำคัญกับการนำทางด้วยเมาส์หรือการกรอง JavaScript แบบ live
คำถามที่พบบ่อย
จะค้นหา key เฉพาะภายในไฟล์ JSON ใน terminal ได้อย่างไร?
ใน jless กด / เพื่อเปิด prompt ค้นหาแบบ incremental พิมพ์ชื่อ key แล้วกด Enter ใช้ n เพื่อกระโดดไปข้างหน้าผ่านผลลัพธ์ที่ตรงกัน และ N เพื่อกระโดดย้อนกลับ การค้นหาเป็น case-sensitive ตามค่าเริ่มต้น ใน jq -C | less -R นั้น / จะเปิดการค้นหาในตัวของ less ซึ่งจับคู่ข้อความดิบรวมถึง ANSI color codes — การค้นหาของ jless เชื่อถือได้มากกว่าสำหรับ JSON ที่มีโครงสร้าง
# 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
จะนำทางโครงสร้าง JSON ที่ซ้อนกันลึกๆ ด้วยปุ่มลัดได้อย่างไร?
jless ใช้การนำทางแบบ vim: j/k สำหรับขึ้น/ลง, h เพื่อยุบ node, l เพื่อขยาย กด H เพื่อยุบ node ปัจจุบันและ siblings ทั้งหมดพร้อมกัน — มีประโยชน์สำหรับดูภาพรวมระดับสูงก่อนเจาะลึกไปยัง branch เฉพาะ L ขยายทุกอย่างแบบ recursive เมื่อยุบทุกอย่างไปยังระดับบนสุดแล้ว ขยายเฉพาะเส้นทางที่ต้องการด้วย l
# 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
จะทำให้ output สีของ jq อ่านได้ง่ายขึ้นบน terminal สีเข้มได้อย่างไร?
ตั้งค่าตัวแปร environment JQ_COLORS ด้วย ANSI attribute;color codes สำหรับแต่ละประเภท JSON ตำแหน่งทั้งเจ็ดตามลำดับคือ: null, false, true, ตัวเลข, strings, arrays, objects ใส่ export ใน ~/.bashrc หรือ ~/.zshrc เพื่อใช้กับทุกการเรียก jq สีสด bold ทำงานได้ดีที่สุดบนพื้นหลังสีเข้ม
# 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 .ความแตกต่างระหว่าง jless และ jq . สำหรับดู JSON คืออะไร?
jq . ส่ง output ทั้งหมดไปยัง stdout ในครั้งเดียว สำหรับ responses ที่ยาวกว่าความสูงของ terminal ทุกอย่างที่อยู่เหนือ screenful สุดท้ายจะหายไป — คุณไม่สามารถเลื่อนกลับไปยังจุดเริ่มต้นหรือนำทางไปยัง field เฉพาะโดยไม่ต้องรันคำสั่งซ้ำด้วย filter jless render เอกสารทั้งหมดใน pager แบบต่อเนื่องซึ่งคุณสามารถเลื่อน ค้นหา ยุบ nodes และนำทางด้วยปุ่มลัดโดยไม่สูญเสีย context ใช้ jq . เมื่อต้องการดู payload เล็กๆ อย่างรวดเร็ว ใช้ 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 screenจะดู JSON จาก curl response แบบ interactive ใน terminal ได้อย่างไร?
Pipe curl โดยตรงไปยัง jless ใส่ -s (silent) เสมอเพื่อป้องกัน progress bar ของ curl ไม่ให้ปรากฏใน output jless จะเปิด viewer แบบ interactive พร้อม response ทั้งหมดที่ render เป็นแผนผังที่ยุบได้ หาก jless ไม่ได้ติดตั้ง jq -C . | less -R ให้ pager ที่มีสีเป็น fallback
# 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
ฉันสามารถดูไฟล์ JSON หลายไฟล์แบบเคียงข้างกันใน terminal ได้ไหม?
jless เปิดไฟล์ทีละไฟล์ สำหรับการเปรียบเทียบแบบเคียงข้างกัน ใช้ terminal multiplexer: tmux split-window -h เปิด split แนวตั้ง จากนั้นรัน jless ในแต่ละ pane ด้วยไฟล์ต่างกัน หรือใช้เครื่องมือ JSON Diff บนเบราว์เซอร์หากต้องการเปรียบเทียบโครงสร้างของสองเอกสาร
# 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)
เครื่องมือที่เกี่ยวข้อง
เครื่องมือ จัดรูปแบบ JSON สวยงาม ให้มุมมองที่ยุบได้และมีสีเหมือนกับ jless — โดยตรงในเบราว์เซอร์ ไม่ต้องติดตั้ง และไม่ต้องใช้ 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.