pretty-print json
Show JSON indented and coloured, pick values out of it, from a file or a web request.
textdevelopment
steps
-
jq . file.jsonthe file, indented and coloured
-
curl -s https://api.example.com/items | jq .a web answer, the same way
-
jq '.items[0].name' file.jsonone value out of it
-
jq -r '.items[].name' file.jsona value from every item, as plain text
-
python3 -m json.tool file.jsonwithout jq: indented by Python
notes
- jq is a package of its own on most systems:
sudo apt install jq,brew install jq.
commands used
jqcurlpython3
Each has a page in lore: lore jq opens it.
count lines of code
How many lines of code a project has, in total and by language.
fix windows line endings
"bad interpreter: ^M" and odd characters: the file has Windows line endings (CRLF). Find them and change them to Unix ones (LF).
read a file line by line
Go through a file's lines in a script, also split into fields, without losing spaces or backslashes.
add up numbers in a file
Sum a column of numbers, from a file or a command's output.