Use jq to convert json array to jsonl format

强颜欢笑 提交于 2020-03-19 05:16:51

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!