问题
I have json like this:
[ {"one": 1}, {"two": 2}]
and wish to convert it to this format:
{"one": 1}
{"two": 2}
to facilitate indexing it into ElasticSearch. (latter is called 'jsonl' format). JQ is my tool of preference but I can't figure out how to do this. Thanks
回答1:
The key is the -c command-line option, which produces JSONL:
jq -c '.[]' test_array.json
回答2:
figured this out:
cat test_array.json |jq '.[]'
回答3:
var json=[ {"one": 1}, {"two": 2}];
for(var i = 0; i < json.length; i++) {
var obj = json[i];
console.log(obj.one);
}
来源:https://stackoverflow.com/questions/48711199/use-jq-to-convert-json-array-to-jsonl-format