英文:
benthos read beautified json
问题
我有一个简单的 JSON:
{
"years": [ "2018", "2019" ]
}
我想用 Benthos 读取它。然而,由于这是一个"美化"的 JSON,Benthos 将每一行都读取为一条消息。如何使用 Benthos 读取这个多行的 JSON,并将其压缩以供后续处理器使用?
input:
file:
paths: [./init.json]
codec: lines/multipart
pipeline:
processors: ??
output:
type: stdout
这个流水线应该简单地将与 jq -c ./init.json
相同的内容打印到 stdout
。
英文:
I have a simple json
{
"years": [ "2018", "2019" ]
}
that I want to read with Benthos. However as this is a "beautified" json, Benthos reads each line as message. How can one read this multiline json with benthos and compactify it for further downstream processors?
input:
file:
paths: [./init.json]
codec: lines/multipart
pipeline:
processors: ??
output:
type: stdout
The pipeline should simply print the same in stdout
as jq -c ./init.json
would.
答案1
得分: 1
请尝试以下内容:
input:
file:
paths: [./init.json]
codec: all-bytes
processors:
- mapping: |
root = this.format_json()
output:
stdout:
codec: all-bytes
另外,请注意当前版本是V4,其中type: stdout
不是指定输出的方式。详细信息请参考这里。
英文:
try this:
input:
file:
paths: [./init.json]
codec: all-bytes
processors:
- mapping: |
root = this.format_json()
output:
stdout:
codec: all-bytes
Also, note that the current release is V4, where type: stdout
isn't how you specify the output. Details here.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论