Documentation
¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
var ( SET = setOption{} MULTISET = multisetOption{} )
var ( COLOR = colorOption{} MERGE = mergeOption{} )
Functions ¶
This section is empty.
Types ¶
type Diff ¶
type Diff []DiffElement
Diff describes how two JsonNodes differ from each other. A Diff is composed of DiffElements (hunks) which describe a difference at a given Path. Each hunk stands alone with all necessary Metadata embedded in the Path, so a Diff rendered in native jd format can easily be edited by hand. The elements of a Diff can be applied to a JsonNode by the Patch method.
func ReadDiffFile ¶
ReadDiffFile reads a file in native jd format.
func ReadDiffString ¶
ReadDiffString reads a string in native jd format.
func ReadMergeFile ¶
ReadMergeFile reads a JSON Merge Patch (RFC 7386) from a file.
func ReadMergeString ¶
ReadMergeString reads a JSON Merge Patch (RFC 7386) from a string.
func ReadPatchFile ¶
ReadPatchFile reads a JSON Patch (RFC 6902) from a file. It is subject to the same restrictions as ReadPatchString.
func ReadPatchString ¶
ReadPatchString reads a JSON Patch (RFC 6902) from a string. ReadPatchString supports a subset of the specification and requires a sequence of "test", "remove", "add" operations which mimics the strict patching strategy of a native jd patch.
For example:
[ {"op":"test","path":"/foo","value":"bar"}, {"op":"remove","path":"/foo","value":"bar"}, {"op":"add","path":"/foo","value":"baz"} ]
func (Diff) RenderMerge ¶
func (Diff) RenderPatch ¶
type DiffElement ¶
type DiffElement struct { // Metadata describes how this DiffElement should be // interpretted. It is also inherited by following // DiffElements until another Metadata is encountered. Metadata Metadata // Path elements can be strings to index Objects, numbers to // index Lists and objects to index Sets and Multisets. Path // elements can be preceeded by an Array of Metadata strings to // change how the structure is interpretted. Metadata in lower // case applies to the following path element. Metadata in upper // case applies to the rest of the path. // // For example: // ["foo","bar"] // indexes to 1 in {"foo":{"bar":1}} // ["foo",0] // indexes to 1 in {"foo":[1]} // ["foo",{}] // indexes a set under "foo" in {"foo":[1]} // ["foo",["multiset"],{}] // indexes a multiset under "foo" in {"foo":[1,1]} // ["foo",{"id":"bar"},"baz"] // indexes to 1 in {"foo":[{"id":"bar","baz":1}]} // [["MERGE"],"foo","bar"] // indexes to 1 in {"foo":{"bar":1}} with merge semantics Path Path // Before are the required context which should appear before // new and old values of a diff element. They are only used // for diffs in a list element. Before []JsonNode // Remove are removed from the JsonNode at the Path. Usually // only one old value is provided unless removing entries from // a Set or Multiset. When using merge semantics no old values // are provided (new values stomp old ones). Remove []JsonNode // Add are added to the JsonNode at the Path. Usually only one // new value is provided unless adding entries to a Set or // Multiset. Add []JsonNode // After are the required context which should appear after // new and old values of a diff element. They are only used // for diffs in a list element. After []JsonNode }
DiffElement (hunk) is a way in which two JsonNodes differ at a given Path. OldValues can be removed and NewValues can be added. The exact Path and how to interpret the intervening structure is determined by a list of JsonNodes (path elements).
func (DiffElement) Render ¶
func (d DiffElement) Render(opts ...Option) string
type JsonNode ¶
type JsonNode interface { // Json renders a JsonNode as a JSON string. Json(renderOptions ...Option) string // Yaml renders a JsonNode as a YAML string in block format. Yaml(renderOptions ...Option) string // Equals returns true if the JsonNodes are equal according to // the provided Metadata. The default behavior (no Metadata) is // to compare the entire structure down to scalar values treating // Arrays as orders Lists. The SET and MULTISET Metadata will // treat Arrays as sets or multisets (bags) respectively. To deep // compare objects in an array irrespective of order, the SetKeys // function will construct Metadata to compare objects by a set // of keys. If two JsonNodes are equal, then Diff with the same // Metadata will produce an empty Diff. And vice versa. Equals(n JsonNode, options ...Option) bool // Diff produces a list of differences (Diff) between two // JsonNodes such that if the output Diff were applied to the // first JsonNode (Patch) then the two JsonNodes would be // Equal. The necessary Metadata is embeded in the Diff itself so // only the Diff is required to Patch a JsonNode. Diff(n JsonNode, options ...Option) Diff // Patch applies a Diff to a JsonNode. No Metadata is provided // because the original interpretation of the structure is // embedded in the Diff itself. Patch(d Diff) (JsonNode, error) // contains filtered or unexported methods }
JsonNode is a JSON value, collection of values, or a void representing the absense of a value. JSON values can be a Number, String, Boolean or Null. Collections can be an Object, native JSON array, ordered List, unordered Set or Multiset. JsonNodes are created with the NewJsonNode function or ReadJson* and ReadYaml* functions.
func NewJsonNode ¶
NewJsonNode constructs a JsonNode from native Golang objects. See the function source for supported types and conversions. Slices are always placed into native JSON Arrays and interpretated as Lists, Sets or Multisets based on Metadata provided during Equals and Diff operations.
func ReadJsonFile ¶
ReadJsonFile reads a file as JSON and constructs a JsonNode.
func ReadJsonString ¶
ReadJsonString reads a string as JSON and constructs a JsonNode.
func ReadYamlFile ¶
ReadYamlFile reads a file as YAML and constructs a JsonNode.
func ReadYamlString ¶
ReadJsonString reads a string as YAML and constructs a JsonNode.
type Path ¶
type Path []PathElement
type PathElement ¶
type PathElement interface {
// contains filtered or unexported methods
}
type PathMultiset ¶
type PathMultiset struct{}