jsonoscope

package module
v0.0.0-...-8547e7d Latest Latest
Warning

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

Go to latest
Published: Feb 20, 2017 License: BSD-3-Clause Imports: 8 Imported by: 0

README

jsonoscope GoDoc

Package jsonoscope contains tooling for structural analysis of JSON documents. It implements depth-first tree traversal of JSON trees and invokes visitor methods for the entry and exit of each node.

Documentation

Overview

Package jsonoscope contains tooling for structural analysis of JSON documents.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Equal

func Equal(r1, r2 io.Reader) (bool, error)

Equal indicates whether the two Readers contain semantically identical JSON data by comparing the signatures of their root JSON objects.

func Recurse

func Recurse(r io.Reader, vis Visitor) error

Recurse performs a depth-first search over a JSON tree and invokes the methods of the provided Visitor for each value in the tree.

Types

type CountingVisitor

type CountingVisitor int

CountingVisitor tallies the number of visited nodes in a JSON tree.

func (*CountingVisitor) Enter

func (cv *CountingVisitor) Enter(path string, token Token)

Enter implements the Visitor interface. It has no effect.

func (*CountingVisitor) Exit

func (cv *CountingVisitor) Exit(path string, token Token, signature []byte)

Exit implements the Visitor interface. It increments the counter by one.

func (*CountingVisitor) Nodes

func (cv *CountingVisitor) Nodes() int

Nodes returns the count of total visited nodes.

type CustomVisitor

type CustomVisitor struct {
	OnEnter func(path string, token Token)
	OnExit  func(path string, token Token, signature []byte)
}

CustomVisitor is a Visitor implementation whose functionality can be dynamically configured for convenience.

func (CustomVisitor) Enter

func (cv CustomVisitor) Enter(path string, token Token)

Enter implements the Visitor interface by invoking the OnEnter callback, if one exists. Otherwise this method has no effect.

func (CustomVisitor) Exit

func (cv CustomVisitor) Exit(path string, token Token, signature []byte)

Exit implements the Visitor interface by invoking the OnExit callback, if one exists. Otherwise this method has no effect.

type Token

type Token int

Token indicates the type of the value at a given JSON path. It is always one of: Null, Number, Boolean, String, Array, or Object.

const (
	Null Token = 1 + iota
	Number
	Boolean
	String
	Array
	Object
)

func (Token) String

func (t Token) String() string

String returns a string in the set {Null, Number, Boolean, String, Array, Object}, or "<unknown>" if the value of Token t is invalid.

type Visitor

type Visitor interface {
	// Enter is invoked when a node in the JSON tree is first reached. It is
	// supplied with the node's path and type.
	Enter(path string, token Token)

	// Enter is invoked on a node when its subtree (if any) has been fully
	// traversed. Invocations of Enter are matched one-to-one with calls
	// to Exit, and exit is provided the same token and path as Enter was.
	//
	// Exit is additionally provided with the node's signature, or a
	// semantically-deterministic hash of its contents.
	Exit(path string, token Token, signature []byte)
}

Visitor defines methods that are invoked during the depth-first traversal of a JSON object.

Jump to

Keyboard shortcuts

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