Json
Tools
Use ~/projects/json/github-array.json
as example json
export JSON=~/projects/json/github-array.json
jq
See jq.md
jc
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
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
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.
Linting json
check-jsonschema
Buildin schemas
- Builtin schemas
- see also src/check_jsonschema/builtin_schemas
- The '--builtin-schema' flag supports the following schema names:
- vendor.azure-pipelines
- vendor.bamboo-spec
- vendor.bitbucket-pipelines
- vendor.buildkite
- vendor.circle-ci
- vendor.cloudbuild
- vendor.dependabot
- vendor.drone-ci
- vendor.github-actions
- vendor.github-workflows
- vendor.gitlab-ci
- vendor.readthedocs
- vendor.renovate
- vendor.taskfile
- vendor.travis
- vendor.woodpecker-ci
- custom.github-workflows-require-timeout
Here the most interesting:
gitlab-ci
- Validate GitLab CI config against the schema provided by SchemaStoregithub-actions
github-workflows
readthedocs
renovate
Install
sudo pacman -S check-jsonschema
cli usage
Builtin schema:
check-jsonschema --builtin-schema vendor.gitlab-ci .gitlab-ci.yml
Schema URL:
check-jsonschema -v \
--schemafile https://raw.githubusercontent.com/goss-org/goss/master/docs/schema.yaml \
goss.yaml
remote schemas
pre-commit usage
repos:
- repo: https://github.com/python-jsonschema/check-jsonschema
rev: 0.23.2
hooks:
- id: check-gitlab-ci
Different jsonlint
linters
- zaach/jsonlint: javascript, supported
by null-ls
brew install jsonlint
- python3-demjson: Unmaintained, last commit 2015
- Seldaek/jsonlint: php, unmaintained
Json definitions / extensions
- 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