benthos读取美化后的JSON。

huangapple go评论76阅读模式
英文:

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.

huangapple
  • 本文由 发表于 2023年4月21日 00:31:14
  • 转载请务必保留本文链接:https://go.coder-hub.com/76066383.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定