You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: _data-prepper/pipelines/configuration/processors/write-json.md
+108Lines changed: 108 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -23,3 +23,111 @@ Option | Description | Example
23
23
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\"}}"`.
24
24
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`
25
25
26
+
## Example
27
+
28
+
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:
29
+
30
+
```yaml
31
+
write-json-demo-pipeline:
32
+
source:
33
+
http:
34
+
path: /logs
35
+
ssl: false
36
+
37
+
processor:
38
+
# 1) Copy the nested "details" object into a JSON string at "details_json"
39
+
- write_json:
40
+
source: details
41
+
target: details_json
42
+
43
+
# 2) Overwrite "payload" with its JSON-string representation
44
+
- write_json:
45
+
# no target -> result stored back into "payload"
46
+
source: payload
47
+
sink:
48
+
- opensearch:
49
+
hosts: ["https://opensearch:9200"]
50
+
insecure: true
51
+
username: admin
52
+
password: admin_pass
53
+
index_type: custom
54
+
index: write-json-demo-%{yyyy.MM.dd}
55
+
```
56
+
{% include copy.html %}
57
+
58
+
You can test this pipeline using the following command:
0 commit comments