Skip to content

Json

Tools

Use ~/projects/json/github-array.json as example json

export JSON=~/projects/json/github-array.json

fx

command-line tool and terminal JSON viewer

jnv

  • GitHub
  • Interactive rust JSON filter using jq

jq

See jq.md

jc

Github:

CLI tool and python library that converts the output of popular command-line tools, file-types, and common strings to JSON, YAML, or Dictionaries. This allows piping of output to tools like jq and simplifying automation scripts

Install:

sudo pacman -S jc

Usage:

dig example.com | jc --dig

Convert INI file to json:

cat ~/.config/git/config | jc --ini

dasel

  • GitHub
  • Docs
  • HCL support was added in v3, which is still unreleased
dasel -f $JSON '.[0].author.id

From stdin:

echo '{ "name": "d" } ' | dasel -f - -r json '.name'

gron

gron "https://api.github.com/repos/tomnomnom/gron/commits?per_page=1" | fgrep "commit.author"
gron "https://api.github.com/repos/tomnomnom/gron/commits?per_page=1" | fgrep "commit.author" | ungron

cat ~/leap/git/bitmask/provider.json | grep -v '//'| gron | grep contacts | ungron

jgrep

http://jgrep.org/

not available via .deb, only via gem:

gem install jgrep

curl -s ipinfo.io | jgrep -s ip

python

 echo '{"first_key": "value", "second_key": "value2"}' | \
   python -c 'import sys,json; print json.dumps({sys.argv[1]:json.load(sys.stdin)[sys.argv[1]]})' first_key

json.sh

https://github.com/dominictarr/JSON.sh

oq

https://blacksmoke16.github.io/oq/ https://github.com/Blacksmoke16/oq

A performant, and portable jq wrapper to facilitate the consumption and output of formats other than JSON; using jq filters to transform the data.

Json definitions / extensions

  • Good overview: Awesome JSON - What’s Next?
  • HuJSON
    • comments + tailing commas
    • impelments the JWCC extension
  • jsonc: json like config with comments
  • hjson "Hjson is a syntax extension to JSON. It's NOT a proposal to replace JSON or to incorporate it into the JSON spec itself. It's intended to be used like a user interface for humans, to read and edit before passing the JSON data to the machine."
  • json5: JSON5 is an extension to the popular JSON file format that aims to be easier to write and maintain by hand (e.g. for config files).
  • jsonl: Newline delimited JSON
  • ndjson Newline Delimited JSON

Convert jsonc to json

sudo pacman -S python-json5

cat ~/.config/waybar/config.jsonc | pyjson5 --as-json | jq

Convert jsonl to json

jsonl -> json:

jq -s '.' input.jsonl > output.json

json -> jsonl:

jq -c '.[]' input.json > output.jsonl

Produce tables from json

see ./tables.md