|
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 whateverOutput: This is fine I guess, but is there a pure-Miller way to do it? Bonus points if it's concise. |
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 |
Hi @smammy !
jqis perhaps a bit more natural here, as it puts maps (objects) and arrays (lists) on equal footing. Sojq .a test.jsonis 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