json

package
v1.8.8 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 27, 2024 License: Apache-2.0 Imports: 8 Imported by: 0

README

JSON 处理

该插件可对指定的字段进行 JSON 展开。

参数说明

插件类型(type)为 processor_json

参数 类型 必选或可选 参数说明
SourceKey string 必选 要展开的源key。
NoKeyError bool 可选 无匹配key是否记录,默认为true。
ExpandDepth int 可选 非负整数,展开深度,0是不限制,1是当前层,默认为0。
ExpandConnector string 可选 展开时的连接符,可以为空,默认为_。
Prefix string 可选 json解析出Key附加的前缀,默认为空。
KeepSource bool 可选 是否保留源字段,默认为true。
UseSourceKeyAsPrefix bool 可选 源key是否作为所有展开key的前缀,默认为false。
示例

对字段 s_key 进行 JSON 展开,配置详情及处理结果如下:

  • 输入
"s_key":"{\"k1\":{\"k2\":{\"k3\":{\"k4\":{\"k51\":\"51\",\"k52\":\"52\"},\"k41\":\"41\"}}})"
  • 配置详情
{
  "processors":[
    {
      "type":"processor_json",
      "detail": {
        "SourceKey": "s_key",
        "NoKeyError":true,
        "ExpandDepth":0,
        "ExpandConnector":"-",
        "Prefix":"j",
        "KeepSource": false,
        "UseSourceKeyAsPrefix": true
      }
    }
  ]
}
  • 配置后结果
"js_key-k1-k2-k3-k4-k51":"51"
"js_key-k1-k2-k3-k4-k52":"52"
"js_key-k1-k2-k3-k41":"41"

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type ExpandParam

type ExpandParam struct {
	// contains filtered or unexported fields
}

func (*ExpandParam) ExpandJSONCallBack

func (p *ExpandParam) ExpandJSONCallBack(key []byte, value []byte, dataType jsonparser.ValueType, _ int) error

type ProcessorJSON

type ProcessorJSON struct {
	SourceKey              string
	NoKeyError             bool
	ExpandDepth            int    // 0是不限制,1是当前层
	ExpandConnector        string // 展开时的连接符,可以为空,默认为_
	Prefix                 string // 默认为空,json解析出Key附加的前缀
	KeepSource             bool   // 是否保留源字段
	KeepSourceIfParseError bool
	UseSourceKeyAsPrefix   bool // Should SourceKey be used as prefix for all extracted keys.
	IgnoreFirstConnector   bool // 是否忽略第一个Connector
	ExpandArray            bool // 是否展开数组类型
	// contains filtered or unexported fields
}

func (*ProcessorJSON) Description

func (*ProcessorJSON) Description() string

func (*ProcessorJSON) Init

func (p *ProcessorJSON) Init(context pipeline.Context) error

Init called for init some system resources, like socket, mutex...

func (*ProcessorJSON) Process added in v1.7.1

func (*ProcessorJSON) ProcessLogs

func (p *ProcessorJSON) ProcessLogs(logArray []*protocol.Log) []*protocol.Log

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL