RUSON
.
parsing json compliant with rfc8259
.
source code does not contain any third party dependencies (why? single source of truth).
-
Installation
- from source
-
Usage
- Synopsis
- Arguments
- Query Syntax
- Examples
INSTALLATION
From source.
Requirements:
- rust and cargo
- gnu make
git clone --depth=1 https://github.com/lycuid/ruson.git
cd ruson
make && sudo make install
USAGE
SYNOPSIS
ruson [OPTIONS]... FILE
FILE
can be replaced with -
(hyphen) or skipped entirely to read json text from standard input.
ARGUMENTS
-p
, --pretty
Print pretty formatted 'json'.
-t
, --table
Print table formatted 'json'.
-q query
, --query[=query]
Text for extracting desired json subtree. query text can be any valid javascript syntax of object property accessors or array indexing.
Query Syntax.
Dot notation.
echo '{ "prop": "value" }' | ruson --query '.prop' # "value"
Bracket notation.
echo '{ "prop": "value" }' | ruson --query '["prop"]' # "value"
Array indexing.
echo '{ "prop": [1, 2, 3, 4, 5] }' | ruson --query '.prop[2]' # 3
.keys()
Function.
echo '{ "one": 1, "two": 2, "three": 3 }' | ruson -q '.keys()' # ["one", "two", "three"]
.values()
function.
echo '{ "one": 1, "two": 2, "three": 3 }' | ruson -q '.values()' # [1, 2, 3]
.length()
function.
echo '[1, 2, 3]' | ruson -q '.length()' # 3
.map()
function.
echo '{ "list": [{ "id": 1 }, { "id": 2 }, { "id": 3 }] }' | ruson -q'.list.map(.id)' # [1, 2, 3]
EXAMPLES
Download latest xkcd
comic
curl https://xkcd.com/info.0.json | ruson -q ".img" | xargs wget
Pokemon attack names.
curl https://pokeapi.co/api/v2/pokemon/pikachu | ruson -q ".moves[0].move.name"
LICENCE
GPLv3