-
Say I have a JSON document like: {
"a": [
{"x":1, "y":2, "z":3},
{"x":4, "y":5, "z":6},
{"x":7, "y":8, "z":9}
],
"b":[
{"i":1, "j":2},
{"i":3, "j":4},
{"i":5, "j":6}
]
} and I'm only interested in the records inside "a". What I usually do is extract the relevant subtree with jq and pass that to Miller: cat test.json | jq .a | mlr --j2p cat # or whatever Output:
This is fine I guess, but is there a pure-Miller way to do it? Bonus points if it's concise. |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 1 reply
-
Hi @smammy !
Miller is a record processor -- it takes as Millerable JSON input (see also here:
This means that the most intuitive idea does not work:
A second optional (not bonus-level concise IMO) is
A third option is to rely on the fact that
This is nice and concise IMO. However, there's that dangling
|
Beta Was this translation helpful? Give feedback.
-
#1513 was more subtle than I thought -- so @smammy I'm going with suggestion two above as my answer to your question. |
Beta Was this translation helpful? Give feedback.
Hi @smammy !
jq
is perhaps a bit more natural here, as it puts maps (objects) and arrays (lists) on equal footing. Sojq .a test.json
is fine whether the value at the"a"
key is a scalar, list, or object.Miller is a record processor -- it takes as Millerable JSON input (see also here:
This means that the most intuitive idea does not work:
A second optional (not bonus-level concise IMO) is