使用jq将json数组转换为jsonl格式 [英] Use jq to convert json array to jsonl format

查看:386
本文介绍了使用jq将json数组转换为jsonl格式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有这样的json:

[ {"one": 1}, {"two": 2}]

并希望将其转换为以下格式:

and wish to convert it to this format:

{"one": 1}
{"two": 2}

便于将其索引到ElasticSearch中. (后一种称为"jsonl"格式). JQ是我的首选工具,但是我不知道该怎么做. 谢谢

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

推荐答案

关键是-c命令行选项,它生成JSONL:

The key is the -c command-line option, which produces JSONL:

jq -c '.[]' test_array.json

这篇关于使用jq将json数组转换为jsonl格式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆