0

我正在尝试将 json 输入包含在其他一些 json 中。我无法掌握过滤器的工作原理,我需要一个应用程序示例。

我的json输入:

{
  "documents": {
      "name": "projects",
      "fields": {
        "done": {
          "booleanValue": false
        },
        "title": {
          "stringValue": "testtest"
        }
      },
      "createTime": "2018-10-09T10:16:45.835536Z",
      "updateTime": "2018-10-09T10:17:37.550249Z"
    }
}

输出应该是:

{
 "fields": {
  "test": {
   "stringValue": "{\"documents\": {\"name\": \"projects\",\"fields\": {\"done\": {\"booleanValue\": false},\"title\": {\"stringValue\": \"testtest\"}},\"createTime\": \"2018-10-09T10:16:45.835536Z\",\"updateTime\": \"2018-10-09T10:17:37.550249Z\"}}"
  }
 }
}
4

2 回答 2

0

假设您有输入,就像您展示的那样,最肮脏的解决方案是之前修改 JSON。

#!/bin/bash
echo -e "{\"fields\":{\"test\":{\"stringValue\":\"" >> newjson.json
cat yourjson.json >> newjson.json
echo -e "\"}}}" >> newjson.json
于 2018-10-12T10:19:34.143 回答
0

解决方案:

filter {
  mutate {
        rename => ["\"", "\\""]
  }
  mutate {
        rename => { "message" => "[stringValue]" }
  }
  mutate {
        rename => { "stringValue" => "[test][stringValue]"}
  }
  mutate {
        rename => { "test" => "[fields][test]"}
  }
  mutate {
    remove_field => ["@timestamp", "@version"]
  }
}
于 2018-10-15T11:52:09.143 回答