-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathjson_outline
More file actions
executable file
·48 lines (45 loc) · 1.11 KB
/
json_outline
File metadata and controls
executable file
·48 lines (45 loc) · 1.11 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
#!/bin/bash
# json_outline - A tool to display JSON structure without values
# Usage: json_outline [file] or cat file.json | json_outline
#
#
# Handy tool to have a quick look at json outline,
# good if you have json with long strings, to look on keys structure first.
#
# can take filename as parameter or stdin.
#
# example:
#
# ```
# $ echo '{"code": 200, "data": {"title": "Test", "nested": {"value": 123}}}' |
# ./json_outline
# {
# "code": ...
# "data": {
# "title": ...
# "nested": {
# "value": ...
# }
# }
# }
# ```
# Check if jq is installed
if ! command -v jq &> /dev/null; then
echo "Error: jq is not installed. Please install it first."
echo "On Debian/Ubuntu: sudo apt install jq"
echo "On Fedora/RHEL: sudo dnf install jq"
echo "On Arch Linux: sudo pacman -S jq"
exit 1
fi
# Process input (either file or stdin)
if [ $# -eq 1 ]; then
# Input from file
if [ ! -f "$1" ]; then
echo "Error: File '$1' not found."
exit 1
fi
jq -r . "$1" | sed 's/: \([^{[].*\)/: .../g'
else
# Input from stdin
jq -r . | sed 's/: \([^{[].*\)/: .../g'
fi