Documentation ¶
Overview ¶
Package transform package contains canonical implementations of Kazaam transforms.
Index ¶
- Constants
- Variables
- func Coalesce(spec *Config, data []byte) ([]byte, error)
- func Concat(spec *Config, data []byte) ([]byte, error)
- func Conditional(spec *Config, data []byte) ([]byte, error)
- func Default(spec *Config, data []byte) ([]byte, error)
- func DelJSONRaw(data []byte, path string, pathRequired bool) ([]byte, error)
- func Delete(spec *Config, data []byte) ([]byte, error)
- func Extract(spec *Config, data []byte) ([]byte, error)
- func GetJSONRaw(data []byte, path string, pathRequired bool) ([]byte, error)
- func HandleUnquotedStrings(value []byte, dt jsonparser.ValueType) []byte
- func Merge(spec *Config, data []byte) ([]byte, error)
- func Pass(spec *Config, data []byte) ([]byte, error)
- func SetJSONRaw(data, out []byte, path string) ([]byte, error)
- func Shift(spec *Config, data []byte) ([]byte, error)
- func Size(spec *Config, data []byte) ([]byte, error)
- func Steps(spec *Config, data []byte) ([]byte, error)
- func Timestamp(spec *Config, data []byte) ([]byte, error)
- func UUID(spec *Config, data []byte) ([]byte, error)
- type BasicExpr
- type CPathSkipError
- type Config
- type JSONPathConverter
- type JSONPathParameters
- type JSONValue
- func (v *JSONValue) GetBoolValue() bool
- func (v *JSONValue) GetData() []byte
- func (v *JSONValue) GetFloatValue() float64
- func (v *JSONValue) GetIntValue() int64
- func (v *JSONValue) GetNumber() json.Number
- func (v *JSONValue) GetQuotedStringValue() string
- func (v *JSONValue) GetStringValue() string
- func (v *JSONValue) GetType() int
- func (v *JSONValue) GetValue() interface{}
- func (v *JSONValue) IsBool() bool
- func (v *JSONValue) IsNull() bool
- func (v *JSONValue) IsNumber() bool
- func (v *JSONValue) IsString() bool
- func (v *JSONValue) SetFloatStringPrecision(p int)
- func (v *JSONValue) String() string
- type ParseError
- type RequireError
- type SpecError
- type TransformFunc
Constants ¶
const ( JSONNull = iota JSONString JSONInt JSONFloat JSONBool )
Variables ¶
var ( ConditionalPathSkip = CPathSkipError("Conditional Path missing and without a default value") NonExistentPath = RequireError("Path does not exist") )
Functions ¶
func Coalesce ¶
Coalesce checks multiple keys and returns the first matching key found in raw []byte.
func Concat ¶
Concat combines any specified fields and literal strings into a single string value with raw []byte.
func Conditional ¶
Shift moves values from one provided json path to another in raw []byte.
func Delete ¶
Delete deletes keys in-place from the provided data if they exist keys are specified in an array under "keys" in the spec.
func HandleUnquotedStrings ¶
func HandleUnquotedStrings(value []byte, dt jsonparser.ValueType) []byte
jsonparser strips quotes from returned strings, this adds them back
func Merge ¶
Merge joins multiple array values into array of objects with property names containing their matching array. Arrays should be the same length.
func Pass ¶
Pass performs no manipulation of the passed-in data. It is useful for testing/default behavior.
Types ¶
type BasicExpr ¶
type BasicExpr struct {
// contains filtered or unexported fields
}
support for basic expression evaluation support. NOTE: expressions must evaluate to a bool value, i.e. true or false supports
! - unary not operator
&& - binary logical and || - binary logical or == - binary equality != - binary equality negated < - binary less than > - binary greater than <= - binary less than or equal to >= - binary greater than or equal to ( ) - parentheses grouping true - boolean true constant false - boolean false constant <number constants> - number constants <string constants> - string constants ( "" ) <func calls> - converter function call, f( jsonPath, stringArgs ) where, f is a converter id, jsonPath is a json path, and args are arguments to the converter <json path resolution> - a json path.. does not support path parameters, i.e. ? conditionals and converter extensions
func NewBasicExpr ¶
json data for evaluating json paths, and the expression string to evaluate to a boolean true/false constant value err will be returned if the expression can't be parsed
type CPathSkipError ¶
type CPathSkipError string
CPathNoDefaultError thrown when a path is missing, and marked conditional, and didn't have a default set
func (CPathSkipError) Error ¶
func (c CPathSkipError) Error() string
type Config ¶
type Config struct { Spec *map[string]interface{} `json:"spec"` Require bool `json:"require,omitempty"` InPlace bool `json:"inplace,omitempty"` }
Config contains the options that dictate the behavior of a transform. The internal `spec` object can be an arbitrary json configuration for the transform.
type JSONPathConverter ¶
type JSONPathConverter struct {
// contains filtered or unexported fields
}
func NewJSONPathConverter ¶
func NewJSONPathConverter(converter string) *JSONPathConverter
type JSONPathParameters ¶
type JSONPathParameters struct {
// contains filtered or unexported fields
}
[jsonPath]?[conditional]|[converter] e.g. root.node1[1].property ? root.node0.prop1 == "true" | regex remove_commas the path will be broken into 3 components: 1. the json parser path to the node value 2. the conditional component 3. and a series of converter expressions to pipe the value through. The conditional component has 4 forms: root.prop1 ? // if the value exists, return it, otherwise skip it, regardless on // whether paths are required. root.prop1 ? defaultVal // if value exists, use that, otherwise return the default value. this is JSON syntax // so strings, will require double quotes. root.prop1 ? root.node1.prop2 == true : // if value exists, and the expression is true, return the existing value // if the value exists, and the expression is false, skip the existing value // note that the : is required here to end the expression. root.prop1 ? root.node1.prop2 == true : defaultValue // if the value exists, and the expression is true, return the existing value // if the value exists and the expression is false, // return the default value (JSON syntax) Conditional Expressions support () , <, >, >=, <=, ==, !=, !, true, false, && and || Conditional expressions must evaluate to a boolean true or false value. Identifiers in the expression are assumed to be JSON paths within the document, and will evaluate to their current value. Only non composite JSON values are supported: boolean, number, string (i.e. not arrays or objects). Function calls of the form <converter name>( json.path, "converter arguments") are also supported, e.g. root.prop1 ? ston(root.node1.prop1) == 3 && regex(root.node2.prop2,"remove_commas) == "1000" : The converters component will define a series of value conversions
func NewJSONPathParameters ¶
func NewJSONPathParameters(data []byte, path string) *JSONPathParameters
type JSONValue ¶
type JSONValue struct {
// contains filtered or unexported fields
}
func GetJsonPathValue ¶
returns a Value (json value type) from the json data byte array, and string path
func NewJSONValue ¶
returns a Value (json value type) from the byte array data for a value
func (*JSONValue) GetBoolValue ¶
func (*JSONValue) GetFloatValue ¶
func (*JSONValue) GetIntValue ¶
func (*JSONValue) GetQuotedStringValue ¶
func (*JSONValue) GetStringValue ¶
func (*JSONValue) SetFloatStringPrecision ¶
type ParseError ¶
type ParseError string
ParseError should be thrown when there is an issue with parsing any of the specification or data
func (ParseError) Error ¶
func (p ParseError) Error() string
type RequireError ¶
type RequireError string
RequireError should be thrown if a required key is missing in the data
func (RequireError) Error ¶
func (r RequireError) Error() string