3 ms·
I appreciate jq and use it almost every day. At the same time, I recently had a task that was easier to do in Node.js. I had a file containing a JSON object w
by beamatronic 12y ago
I appreciate jq and use it almost every day. At the same time, I recently had a task that was easier to do in Node.js. I had a file containing a JSON object with a structure like so: [ { }, { }, ... ] and I wanted to turn each object into a separate file.
- TheDong 12y agoThat task is trivially accomplishable in jq. I have no clue why you say it's "easier" in nodejs. i=1 for line in `echo '[{"a":"b"},{"c":"d"},{"e":"f"}]' | jq '.[]' -c`; do echo $line | jq '.' > jq_out_$i.json i=$((i+1)) done The above prints each element of the array to a file named by its index, including pretty-printing it. If you use it every day, the above should have come to you easily enough.