小编sha*_*dfc的帖子

流畅的嵌套json解析

我有如下日志:

{
  "log": {
    "header": {
      "key": "value",
      "nested": "{\"key1\":\"value\",\"key2\":\"value\"}",
      "dateTime": "2019-05-08T20:58:06+00:00"
    },
    "body": {
      "path": "/request/path/",
      "method": "POST",
      "ua": "curl/7.54.0",
      "resp": 200
    }
  }
}
Run Code Online (Sandbox Code Playgroud)

我正在尝试使用 fluentd 聚合日志,并且我希望整个记录都是 JSON。具体问题是“$.log.header.nested”字段,它是一个JSON字符串。如何解析该字符串并将其替换为其内容?

为清楚起见,我希望 fluentd 输出的日志如下所示:

{
  "log": {
    "header": {
      "key": "value",
      "nested": {
          "key1": "value",
          "key2": "value"
      },
      "dateTime": "2019-05-08T20:58:06+00:00"
    },
    "body": {
      "path": "/request/path/",
      "method": "POST",
      "ua": "curl/7.54.0",
      "resp": 200
    }
  }
}
Run Code Online (Sandbox Code Playgroud)

我找到了一种将嵌套字段解析为 JSON 的方法,但存储回它解析的同一个键尚不清楚。似乎不hash_value_field支持存储到嵌套键。有没有其他方法可以实现这一点?

json fluentd

7
推荐指数
1
解决办法
5708
查看次数

标签 统计

fluentd ×1

json ×1