JSON
Synopsis
Parses JSON strings from a specified field into structured objects.
Schema
json:
- field: <ident>
- add_to_root: <boolean>
- add_to_root_conflict_strategy: <enum>
- allow_duplicate_keys: <boolean>
- description: <text>
- if: <script>
- ignore_failure: <boolean>
- ignore_missing: <boolean>
- on_failure: <processor[]>
- on_success: <processor[]>
- tag: <string>
- target_field: <ident>
Configuration
| Field | Required | Default | Description |
|---|---|---|---|
field | Y | - | Source field containing JSON string |
add_to_root | N | false | Add parsed fields to document root |
add_to_root_conflict_strategy | N | replace | Strategy for root conflicts: replace or merge |
allow_duplicate_keys | N | false | Allow duplicate keys in JSON |
description | N | - | Documentation note |
if | N | - | Conditional expression |
ignore_failure | N | false | Skip processing errors |
ignore_missing | N | false | Skip if input field missing |
on_failure | N | - | Error handling processors |
on_success | N | - | Success handling processors |
tag | N | - | Identifier for logging |
target_field | N | - | Output field for parsed object |
Details
The processor can either store the parsed object in a target field or merge it into the document root, with configurable strategies for handling conflicts and duplicate keys.
When add_to_root is set to true, target_field must not be set as fields are added directly to the document root.
The processor supports two strategies for handling conflicts when adding to root:
replace- Existing fields are overwritten with the new valuesmerge- Objects are merged recursively, arrays are concatenated, and primitive values are replaced
Setting allow_duplicate_keys to true may lead to unpredictable results as only the last value for a key is retained.
Examples
Basic
Parsing JSON string to object... | |
creates a structured object: | |
Adding to Root
Merging JSON into the document root... | |
replaces the existing values: | |
Merge
Merging nested objects... | |
combines existing and new values: | |
Duplicate Keys
Handling the duplicate keys in JSON... | |
keeps the last value: | |
Error Handling
Handling invalid JSON gracefully... | |
captures the error information: | |