Files
honeymoose f321dfedf5 同步完成!
**同步结果摘要**:

| 目录 | 同步前 | 同步后 | 官方 |
|------|--------|--------|------|
| aggregations | 40 | 65 | 64 |
| analyzers | 8 | 141 | 140 |
| api-reference | 97 | 186 | 174 |
| benchmark | 34 | 67 | 53 |
| clients | 17 | 18 | 18 |
| dashboards | 38 | 149 | 131 |
| data-prepper | 77 | 134 | 123 |
| im-plugin | 22 | 37 | 37 |
| ingest-pipelines | 27 | 52 | 51 |
| install-and-configure | 37 | 57 | 53 |
| ml-commons-plugin | 81 | 157 | 155 |
| observing-your-data | 39 | 73 | 66 |
| query-dsl | 40 | 77 | 75 |
| search-plugins | 80 | 139 | 95 |
| security-analytics | 22 | 47 | 46 |

**说明**:
- 本地文件数 > 官方:本地有一些官方已删除或重命名的文件
- 新增了约 **740 个英文文档文件**
- 已有文件保持不变(未覆盖)
2026-11-30 10:48:30 -05:00

4.2 KiB

layout, title, parent, grand_parent, nav_order, redirect_from
layout title parent grand_parent nav_order redirect_from
default Write JSON Processors Pipelines 440
/data-prepper/pipelines/configuration/processors/write_json/

Write JSON processor

The write_json processor converts an object in an event into a JSON string. You can customize the processor to choose the source and target field names.

Option Description Example
source Mandatory field that specifies the name of the field in the event containing the message or object to be parsed. If source is set to "message" and the input is {"message": {"key1":"value1", "key2":{"key3":"value3"}}}, then the write_json processor outputs the event as "{\"key1\":\"value1\",\"key2\":{\"key3\":\"value3\"}}".
target An optional field that specifies the name of the field in which the resulting JSON string should be stored. If target is not specified, then the source field is used. key1

Example

The following example uses write_json twice, first to copy the details object into a new JSON string field named target and then to overwrite the original payload field when target is omitted:

write-json-demo-pipeline:
  source:
    http:
      path: /logs
      ssl: false

  processor:
    # 1) Copy the nested "details" object into a JSON string at "details_json"
    - write_json:
        source: details
        target: details_json

    # 2) Overwrite "payload" with its JSON-string representation
    - write_json:
        # no target -> result stored back into "payload"
        source: payload   
  sink:
    - opensearch:
        hosts: ["https://opensearch:9200"]
        insecure: true
        username: admin
        password: "<custom-admin-password>"
        index_type: custom
        index: write-json-demo-%{yyyy.MM.dd}

{% include copy.html %}

You can test this pipeline using the following command:

curl -sS -X POST "http://localhost:2021/logs" \
  -H "Content-Type: application/json" \
  -d '[
    {
      "message": "order created",
      "details": {"order_id": 123, "items": [{"sku": "A1", "qty": 2}], "expedited": true},
      "payload": {"user": {"id": "u-42", "role": "admin"}, "ip": "10.0.0.5"}
    },
    {
      "message": "order updated",
      "details": {"order_id": 124, "items": [{"sku": "B9", "qty": 1}], "expedited": false},
      "payload": {"user": {"id": "u-77", "role": "viewer"}, "ip": "10.0.0.9"}
    }
  ]'

{% include copy.html %}

The documents stored in OpenSearch contain the following information:

{
  ...
  "hits" : {
    "total" : {
      "value" : 2,
      "relation" : "eq"
    },
    "max_score" : 1.0,
    "hits" : [
      {
        "_index" : "write-json-demo-2025.10.15",
        "_id" : "YMQA6ZkB1u9wkbZgz8wu",
        "_score" : 1.0,
        "_source" : {
          "message" : "order created",
          "details" : {
            "order_id" : 123,
            "items" : [
              {
                "sku" : "A1",
                "qty" : 2
              }
            ],
            "expedited" : true
          },
          "payload" : "{\"user\":{\"id\":\"u-42\",\"role\":\"admin\"},\"ip\":\"10.0.0.5\"}",
          "details_json" : "{\"order_id\":123,\"items\":[{\"sku\":\"A1\",\"qty\":2}],\"expedited\":true}"
        }
      },
      {
        "_index" : "write-json-demo-2025.10.15",
        "_id" : "YcQA6ZkB1u9wkbZgz8wu",
        "_score" : 1.0,
        "_source" : {
          "message" : "order updated",
          "details" : {
            "order_id" : 124,
            "items" : [
              {
                "sku" : "B9",
                "qty" : 1
              }
            ],
            "expedited" : false
          },
          "payload" : "{\"user\":{\"id\":\"u-77\",\"role\":\"viewer\"},\"ip\":\"10.0.0.9\"}",
          "details_json" : "{\"order_id\":124,\"items\":[{\"sku\":\"B9\",\"qty\":1}],\"expedited\":false}"
        }
      }
    ]
  }
}