Skip to content

Commit

Permalink
feat(logging): Document the isEscaped JSON action config
Browse files Browse the repository at this point in the history
  • Loading branch information
bmcfeely committed May 8, 2024
1 parent 7771a9e commit 1b5f193
Showing 1 changed file with 25 additions and 0 deletions.
25 changes: 25 additions & 0 deletions src/content/docs/logs/ui-data/parsing.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -391,6 +391,30 @@ Note that variable names must be explicitly set and be lowercase like `%{URI:uri
%{TIMESTAMP_ISO8601:containerTimestamp} %{GREEDYDATA:my_attribute_prefix:json({"noPrefix": true, "keepAttributes": ["status"]})}
```

If your JSON has been escaped, you can use the `isEscaped` option to be able to parse it.
If your JSON has been escaped and then quoted, you need to match the quotes as well, as shown below.
For example, with the following Grok expression:

```
%{TIMESTAMP_ISO8601:containerTimestamp} "%{GREEDYDATA:my_attribute_prefix:json({"isEscaped": true})}"
```

Would be able to parse the escaped message:

```
2015-05-13T23:39:43.945958Z "{\"event\": \"TestRequest\", \"status\": 200, \"response\": {\"headers\": {\"X-Custom\": \"foo\"}}, \"request\": {\"headers\": {\"X-Custom\": \"bar\"}}}"
```

The resulting log is:

```
containerTimestamp: "2015-05-13T23:39:43.945958Z"
my_attribute_prefix.event: "TestRequest"
my_attribute_prefix.status: 200
my_attribute_prefix.response.headers.X-Custom: "foo"
my_attribute_prefix.request.headers.X-Custom: "bar"
```

To configure the `json` [Grok type](#grok-syntax), use `:json(_CONFIG_)`:

- `json({"dropOriginal": true})`: Drop the JSON snippet that was used in parsing. When set to `true` (default value), the parsing rule will drop the original JSON snippet. Note the JSON attributes will remain in the message field.
Expand All @@ -399,6 +423,7 @@ To configure the `json` [Grok type](#grok-syntax), use `:json(_CONFIG_)`:
- `json({"keepAttributes": ["attr1", "attr2", ..., "attrN"]})`: Specifies which attributes will be extracted from the JSON. The provided list cannot be empty. If this configuration option is not set, all attributes are extracted.
- `json({"dropAttributes": ["attr1", "attr2", ..., "attrN"]})`: Specifies which attributes to be dropped from the JSON. If this configuration option is not set, no attributes are dropped.
- `json({"noPrefix": true})`: Set this option to `true` to remove the prefix from the attributes extracted from the JSON.
- `json({"isEscaped": true})`: Set this option to `true` to parse JSON that has been escaped (which you typically see when JSON is stringified, for example `{\"key\": \"value\"}`)


</Collapser>
Expand Down

0 comments on commit 1b5f193

Please sign in to comment.