Documentation
¶
Overview ¶
Package json contains the json node implementation.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type JSONConfig ¶
type JSONConfig struct {
// Action selects the conversion: "" (auto: stringify objects, parse
// strings) | "str" (always stringify) | "obj" (always parse)
Action string `json:"action"`
// Property is the message field to convert; "payload" (default)
// targets msg.Payload, otherwise a dotted path inside the data map
Property string `json:"property"`
// Pretty indents stringified output with two spaces
Pretty bool `json:"pretty"`
// Outputs is the node port count; 2 adds a second port that receives
// messages whose JSON failed to parse (error info in Metadata.error)
Outputs int `json:"outputs"`
}
JSONConfig holds configuration for the json node — the Node-RED JSON parser equivalent. Converts the configured property between a JSON string and its decoded object representation.
type JSONNode ¶
JSONNode converts payload data between string and object form.
func NewJSONNode ¶
func NewJSONNode(node nodestore.NodeInterface, config *JSONConfig) *JSONNode
NewJSONNode creates a new json node
func (*JSONNode) Execute ¶
func (n *JSONNode) Execute(ctx context.Context, input nodestore.MessageInterface) (nodestore.MessageInterface, error)
Execute reads the configured property, converts it and writes the result back. A parse failure either routes to output_2 (when the node has two outputs) or aborts the branch with an error status.
func (*JSONNode) SelectPorts ¶
func (n *JSONNode) SelectPorts(input, output nodestore.MessageInterface) []string
SelectPorts routes the message to output_2 when the last Execute hit a parse error, otherwise to output_1.