Skip to main content

json.decode

Decodes a specific field from JSON raw data (string) to structured data.

Description

The processor takes JSON raw data (string or []byte) from the target field, parses it as JSON structured data and stores the decoded structured data in the target field.

This processor is only applicable to fields under .Key, .Payload.Before and .Payload.After, as they can contain structured data.

Configuration parameters

NameTypeDefaultDescription
fieldstring
null

Field is a reference to the target field. Only fields that are under .Key and .Payload can be decoded.

For more information about the format, see Referencing fields.

Examples

Decode record key as JSON

This example takes a record containing a raw JSON string in .Key and converts it into structured data.

Configuration parameters

NameValue
field.Key

Record difference

Before
After
1
{
1
{
2
  "position": null,
2
  "position": null,
3
  "operation": "create",
3
  "operation": "create",
4
  "metadata": null,
4
  "metadata": null,
5
-
  "key": "{\"after\":{\"data\":4,\"id\":3}}",
5
+
  "key": {
6
+
    "after": {
7
+
      "data": 4,
8
+
      "id": 3
9
+
    }
10
+
  },
6
  "payload": {
11
  "payload": {
7
    "before": null,
12
    "before": null,
8
    "after": null
13
    "after": null
9
  }
14
  }
10
}
15
}

Decode nested field as JSON

This example takes a record containing a raw JSON string in .Payload.Before.foo and converts it into a map.

Configuration parameters

NameValue
field.Payload.Before.foo

Record difference

Before
After
1
{
1
{
2
  "position": null,
2
  "position": null,
3
  "operation": "snapshot",
3
  "operation": "snapshot",
4
  "metadata": null,
4
  "metadata": null,
5
  "key": null,
5
  "key": null,
6
  "payload": {
6
  "payload": {
7
    "before": {
7
    "before": {
8
-
      "foo": "{\"before\":{\"data\":4,\"id\":3},\"baz\":\"bar\"}"
8
+
      "foo": {
9
+
        "baz": "bar",
10
+
        "before": {
11
+
          "data": 4,
12
+
          "id": 3
13
+
        }
14
+
      }
9
    },
15
    },
10
    "after": null
16
    "after": null
11
  }
17
  }
12
}
18
}