File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1+ # Jsonflat
2+
3+ Jsonflat is a utility to convert JSONs into flatter, greppable form. Given the following json:
4+
5+ ```
6+ {
7+ "foos": [
8+ {
9+ "name": "a",
10+ "frobnicity": 50
11+ },
12+ {
13+ "name": "b",
14+ "frobnicity": 50
15+ }
16+ ]
17+ }
18+ ```
19+
20+ it spits out:
21+
22+ ```
23+ .foos[0](name=a).frobnicity: 50
24+ .foos[0](name=a).name: "a"
25+ .foos[1](name=b).frobnicity: 50
26+ .foos[1](name=b).name: "b"
27+ ```
28+
29+ Note that ` name ` key is special and is included in paths. This is to make paths
30+ more meaningful if your data representation is not a dict, but rather list of
31+ named objects.
32+
33+ It also works when jsons are embedded in plaintext:
34+
35+ ```
36+ [2020-02-02 20:02] Got response: {
37+ "code": 404,
38+ "message": "nothing there"
39+ }. Ignoring.
40+ ```
41+
42+ ```
43+ [2020-02-02 20:02] Got response: .code: 404
44+ [2020-02-02 20:02] Got response: .message: "nothing there"
45+ [2020-02-02 20:02] Got response: {…}. Ignoring.
46+ ```
47+
48+ ## Usage
49+
50+ Reads from stdin, writes to stdout.
51+
52+ ### Example
53+
54+ ``` sh
55+ command that returns json | jsonflat | grep " thing"
56+ ```
57+
58+ There's also a ` stripcommonprefix ` command included that should help with long paths:
59+
60+ ``` sh
61+ command that returns json | jsonflat | grep " thing" | stripcommonprefix
62+ ```
63+
64+ ## Installation
65+
66+ ### Linux
67+
68+ Check out the releases.
69+
70+ ### Manual
71+
72+ 1 . [ Install Rust] ( https://www.rust-lang.org/tools/install )
73+ 2 . ``` sh
74+ cargo install --git https://github.com/krdln/jsonflat
75+ ```
76+
77+ ## License
78+
79+ TODO
You can’t perform that action at this time.
0 commit comments