transform

package
v0.7.2 Latest Latest
Warning

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

Go to latest
Published: May 29, 2019 License: MIT Imports: 13 Imported by: 0

Documentation

Overview

Package transform implements code which can use a JSON schema with transform sections to convert a JSON file to match the schema format.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type JSONTransformer added in v0.5.7

type JSONTransformer interface {
	Transform(raw json.RawMessage) (json.RawMessage, error)
}

JSONTransformer - a type implemented by the jstransform.Transformer

type Transformer

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

Transformer uses a JSON schema and the transform sections within it to take a set of JSON and transform it to matching the schema. More details on the transform section of the schema are found at https://github.com/GannettDigital/jstransform/blob/master/transform.adoc

func NewTransformer

func NewTransformer(schema *jsonschema.Schema, tranformIdentifier string) (*Transformer, error)

NewTransformer returns a Transformer using the schema given. The transformIdentifier is used to select the appropriate transform section from the schema. It expects the transforms to be performed on JSON data

func NewXMLTransformer added in v0.7.0

func NewXMLTransformer(schema *jsonschema.Schema, tranformIdentifier string) (*Transformer, error)

NewXMLTransformer returns a Transformer using the schema given. The transformIdentifier is used to select the appropriate transform section from the schema. It expects the transforms to be performed on XML data

func (*Transformer) Transform

func (tr *Transformer) Transform(raw json.RawMessage) (json.RawMessage, error)

Transform takes the provided JSON and converts the JSON to match the pre-defined JSON Schema using the transform sections in the schema.

By default fields with no Transform section but with matching path and type are copied verbatim into the new JSON structure. Fields which are missing from the input are set to a default value in the output.

Errors are returned for failures to perform operations but are not returned for empty fields which are either omitted from the output or set to an empty value.

Validation of the output against the schema is the final step in the process.

Jump to

Keyboard shortcuts

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