Skip to content

Latest commit

 

History

History
203 lines (164 loc) · 5.03 KB

json_parser.md

File metadata and controls

203 lines (164 loc) · 5.03 KB

json_parser operator

The json_parser operator parses the string-type field selected by parse_from as JSON.

Configuration Fields

Field Default Description
id json_parser A unique identifier for the operator
output Next in pipeline The connected operator(s) that will receive all outbound entries
parse_from $ A field that indicates the field to be parsed as JSON
parse_to $ A field that indicates the field to be parsed as JSON
preserve_to Preserves the unparsed value at the specified field
on_error send The behavior of the operator if it encounters an error. See on_error
if An expression that, when set, will be evaluated to determine whether this operator should be used for the given entry. This allows you to do easy conditional parsing without branching logic with routers.
timestamp nil An optional timestamp block which will parse a timestamp field before passing the entry to the output operator
severity nil An optional severity block which will parse a severity field before passing the entry to the output operator

Example Configurations

Parse the field message as JSON

Configuration:

- type: json_parser
  parse_from: message
Input record Output record
{
  "timestamp": "",
  "record": {
    "message": "{\"key\": \"val\"}"
  }
}
{
  "timestamp": "",
  "record": {
    "key": "val"
  }
}

Parse a nested field to a different field, preserving original

Configuration:

- type: json_parser
  parse_from: message.embedded
  parse_to: parsed
  preserve: true
Input record Output record
{
  "timestamp": "",
  "record": {
    "message": {
      "embedded": "{\"key\": \"val\"}"
    }
  }
}
{
  "timestamp": "",
  "record": {
    "message": {
      "embedded": "{\"key\": \"val\"}"
    },
    "parsed": {
      "key": "val"
    }
  }
}

Parse the field message as JSON, and parse the timestamp

Configuration:

- type: json_parser
  parse_from: message
  timestamp:
    parse_from: seconds_since_epoch
    layout_type: epoch
    layout: s
Input record Output record
{
  "timestamp": "",
  "record": {
    "message": "{\"key\": \"val\", \"seconds_since_epoch\": 1136214245}"
  }
}
{
  "timestamp": "2006-01-02T15:04:05-07:00",
  "record": {
    "key": "val"
  }
}

Parse the message field only if it starts and ends with brackets

Configuration:

- type: json_parser
  if: '$record matches "^{.*}$"'
Input record Output record
{
  "record": "{\"key\": \"val\"}"
}
{
  "record": {
    "key": "val"
  }
}
{
  "record": "notjson"
}
{
  "record": "notjson"
}