JQ - 如何将带标题的 CSV 转换为带嵌套字典的 JSON 数组
我得到了以下 CSV 示例
key1,key2,key3,key4,key5
val1,val2,val3,val4,val5
寻找如何将上述结构转换为以下 JSON 结构的提示
[
{
"event": "bleep",
"sourcetype": "rats",
"fields": {
"key1":"val1",
"key2":"val2",
"key3":"val3",
"key4":"val4",
"key5":"val5"
}
},
{
"event": "bleep",
"sourcetype": "rats",
"fields": {
"key1":"val1",
"key2":"val2",
"key3":"val3",
"key4":"val4",
"key5":"val5"
}
}
]
提前致谢!
I got the following CSV sample
key1,key2,key3,key4,key5
val1,val2,val3,val4,val5
Looking for tips how to convert the above structure into the following JSON structure
[
{
"event": "bleep",
"sourcetype": "rats",
"fields": {
"key1":"val1",
"key2":"val2",
"key3":"val3",
"key4":"val4",
"key5":"val5"
}
},
{
"event": "bleep",
"sourcetype": "rats",
"fields": {
"key1":"val1",
"key2":"val2",
"key3":"val3",
"key4":"val4",
"key5":"val5"
}
}
]
Thanks in advance!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
使用
-R
将输入读取为原始文本演示
Use
-R
to read the input as raw textDemo
Alasql lib 可以从服务器加载数据文件,解析它并将结果放入 JSON 对象数组。
所以,这是给你的一些例子:
Alasql lib can load the data file from server, parse it and put the result to array of JSON objects.
So, this is some example for you: