Documentation ¶
Overview ¶
Package kazaam provides a simple interface for transforming arbitrary JSON in Golang.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Kazaam ¶
type Kazaam struct {
// contains filtered or unexported fields
}
Kazaam includes internal data required for handling the transformation. A Kazaam object must be initialized using the NewKazaam function.
func NewKazaam ¶
NewKazaam creates a new Kazaam instance by parsing the `spec` argument as JSON and returns a pointer to it. The string `spec` must be valid JSON or empty for NewKazaam to return a Kazaam object.
If empty, the default Kazaam behavior when the Transform variants are called is to return the original data unmodified.
At initialization time, the `spec` is checked to ensure that it is valid JSON. Further, it confirms that all individual specs have a properly-specified `operation` and details are set if required. If the spec is invalid, a nil Kazaam pointer and an explanation of the error is returned. The contents of the transform specification is further validated at Transform time.
func (*Kazaam) Transform ¶
Transform takes the *simplejson.Json `data`, transforms it according to the loaded spec, and returns the modified *simplejson.Json object.
Note: this is a destructive operation: the transformation is done in place. You must perform a deep copy of the data prior to calling Transform if the original JSON object must be retained.
func (*Kazaam) TransformJSONString ¶
TransformJSONString loads the JSON string, transforms it as per the spec, and returns a pointer to a transformed simplejson.Json.
This function is especially useful when one may need to extract multiple fields from the transformed JSON.