]> src.twobees.de Git - dotfiles.git/blob - stow/oh-my-zsh/.oh-my-zsh/plugins/jsontools/README.md
initial
[dotfiles.git] / stow / oh-my-zsh / .oh-my-zsh / plugins / jsontools / README.md
1 # jsontools
2
3 Handy command line tools for dealing with json data.
4
5 To use it, add `jsontools` to the plugins array in your zshrc file:
6
7 ```zsh
8 plugins=(... jsontools)
9 ```
10
11 ## Usage
12
13 Usage is simple... just take your json data and pipe it into the appropriate jsontool:
14
15 - `pp_json`: pretty prints json.
16 - `is_json`: returns true if valid json; false otherwise.
17 - `urlencode_json`: returns a url encoded string for the given json.
18 - `urldecode_json`: returns decoded json for the given url encoded string.
19
20 ### Supports NDJSON (Newline Delimited JSON)
21
22 The plugin also supports [NDJSON](http://ndjson.org/) input, which means all functions
23 have an alternative function that reads and processes the input line by line. These
24 functions have the same name except using `ndjson` instead of `json`:
25
26 > `pp_ndjson`, `is_ndjson`, `urlencode_ndjson`, `urldecode_ndjson`.
27
28 ### Examples
29
30 - **pp_json**:
31
32 ```console
33 # curl json data and pretty print the results
34 curl https://coderwall.com/bobwilliams.json | pp_json
35 ```
36
37 - **is_json**:
38
39 ```console
40 # validate if file's content conforms to a valid JSON schema
41 $ is_json < data.json
42 true
43 # shows true / false and returns the proper exit code
44 $ echo $?
45 0
46 ```
47
48 - **urlencode_json**:
49
50 ```console
51 # json data directly from the command line
52 $ echo '{"b":2, "a":1}' | urlencode_json
53 %7B%22b%22:2,%20%22a%22:1%7D
54 ```
55
56 - **urldecode_json**:
57
58 ```console
59 # url encoded string to decode
60 $ echo '%7B%22b%22:2,%20%22a%22:1%7D' | urldecode_json
61 {"b":2, "a":1}
62 ```
63
64 - **pp_ndjson**:
65
66 ```console
67 # echo two separate json objects and pretty print both
68 $ echo '{"a": "b"}\n{"c": [1,2,3]}' | pp_ndjson
69 {
70     "a": "b"
71 }
72 {
73     "c": [
74         1,
75         2,
76         3
77     ]
78 }
79 ```