@@ -25,47 +25,80 @@ If you're not familiar with associative arrays in bash or how `declare` works, i
2525
2626## Usage
2727
28- please parse [-i type ] [-o type ] [path... ]
28+ please parse [-i <INPUT FORMAT> ] [-o <OUTPUT FORMAT> ] [PATH ]
2929
30- -i type Parse the input as 'type' (default: auto)
31- -o type Use 'type' as the output format (default: bash)
30+ If INPUT TYPE is omitted, it defaults to "auto".
3231
33- If path is given, only output data from the path downwards.
32+ If OUTPUT TYPE is omitted, it will default to the same as the input type - effectively acting as a pretty-printer.
33+
34+ If PATH is provided, it should be given in dot-notation, e.g. orders.*.id
35+
36+ Available input types:
37+ auto
38+ csv
39+ html
40+ json
41+ mime
42+ xml
43+ yaml
44+
45+ Available output types:
46+ bash
47+ dot
48+ json
49+ xml
50+ yaml
3451
3552## Examples
3653
3754Parsing a whole tree:
3855
3956 $ echo '{"this":{"is":["some","json"],"that":"we"},"will":"parse"}' | please parse
40- ([this]="([is]=\"([0]=some [1]=json)\" [that]=we)" [will]=parse)
57+ {
58+ "this": {
59+ "is": [
60+ "some",
61+ "json"
62+ ],
63+ "that": "we"
64+ },
65+ "will": "parse"
66+ }
4167
4268Getting a single value:
4369
4470 $ echo '{"this":{"is":["some","json"],"that":"we"},"will":"parse"}' | please parse this.that
45- we
71+ "we"
4672
4773Specifying the input format:
4874
4975Note the ` -i ` flag
5076
5177 $ echo '<xml example="true"><child>one</child><child>two</child></xml>' | please parse -i xml
52- ([xml]="([-example]=\"true\" [child]=\"([0]=\\\"one\\\" [1]=\\\"two\\\")\")")
78+ <xml example="true">
79+ <child>one</child>
80+ <child>two</child>
81+ </xml>
5382
5483Specifying the output format:
5584
5685Note the ` -o ` flag
5786
5887 $ echo '{"json": ["input", "here"], "yaml": "output"}' | please parse -o yaml
59- ' json' :
60- - " input"
61- - " here"
62- ' yaml': " output"
88+ json:
89+ - input
90+ - here
91+ yaml: output
6392
6493Making use of the bash-declare output format
6594
66- $ echo '{"json": ["array", "values"]} ' | please parse json | (declare -A data=$(cat -); echo ${data[1]})
95+ $ echo '["array", "values"]' | please parse -o bash | (declare -A data=$(cat -); echo ${data[1]})
6796 values
6897
6998Generating a graph from some json (you need graphviz installed)
7099
71100 $ echo '{"vars": ["foo", "bar", "baz"], "cake": {"is_lie": true}}' | please parse -o dot | dot -Tpng > graph.png
101+
102+ Will result in:
103+
104+ ![ A nice graph] ( dot-output.png )
0 commit comments