json

package
v1.0.0-beta6 Latest Latest
Warning

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

Go to latest
Published: Oct 4, 2021 License: Apache-2.0 Imports: 10 Imported by: 1

Documentation

Index

Constants

View Source
const JSON = "https://json.org#"

Variables

View Source
var ArrayTypeTerm = ls.NewTerm(JSON+"array", false, false, ls.OverrideComposition, nil)
View Source
var BooleanTypeTerm = ls.NewTerm(JSON+"boolean", false, false, ls.OverrideComposition, nil)
View Source
var IntegerTypeTerm = ls.NewTerm(JSON+"integer", false, false, ls.OverrideComposition, nil)
View Source
var NumberTypeTerm = ls.NewTerm(JSON+"number", false, false, ls.OverrideComposition, nil)
View Source
var ObjectTypeTerm = ls.NewTerm(JSON+"object", false, false, ls.OverrideComposition, nil)
View Source
var StringTypeTerm = ls.NewTerm(JSON+"string", false, false, ls.OverrideComposition, nil)

Functions

func DefaultBuildNodeKeyFunc

func DefaultBuildNodeKeyFunc(node ls.Node) (string, bool, error)

DefaultBuildNodeKeyFunc returns the attribute name term propertu from the node if it exists. If not, it return false

func GetBuildNodeKeyBySchemaNodeFunc

func GetBuildNodeKeyBySchemaNodeFunc(f func(schemaNode, docNode ls.Node) (string, bool, error)) func(ls.Node) (string, bool, error)

GetBuildNodeKeyBySchemaNodeFunc returns a function that gets the schema node and the doc node. If the doc node does not have a schema node, it is not exported. The function `f` should decide what key to use

func GetBuildNodeKeyExprFunc

func GetBuildNodeKeyExprFunc(closure gl.Closure) func(ls.Node) (string, bool, error)

GetBuildNodeKeyExprFunc returns a function that builds node keys using an expression. The expression should be a closure getting a node argument

func IngestBytes

func IngestBytes(ingester *Ingester, target *digraph.Graph, baseID string, input []byte) (ls.Node, error)

IngestBytes ingests JSON bytes

func IngestStream

func IngestStream(ingester *Ingester, target *digraph.Graph, baseID string, input io.Reader) (ls.Node, error)

IngestStream ingests JSON stream

Types

type Array

type Array struct {
	Elements []OM
}

Array represents a JSON array

func (Array) Encode

func (e Array) Encode(w io.Writer) error

type CompiledEntity

type CompiledEntity struct {
	Entity
	Schema *jsonschema.Schema
}

CompiledEntity contains the JSON schema for the entity

func Compile

func Compile(entities []Entity) ([]CompiledEntity, error)

Compile all entities as a single unit.

func CompileWith

func CompileWith(compiler *jsonschema.Compiler, entities []Entity) ([]CompiledEntity, error)

CompileWith compiles all entities as a single unit using the given compiler

type Entity

type Entity struct {
	Name       string `json:"name"`
	Ref        string `json:"ref"`
	ID         string `json:"id"`
	SchemaName string `json:"schema"`
}

Entity gives an entity name to a location in a schema

func (Entity) GetEntityName

func (e Entity) GetEntityName() string

GetEntityName returns the ID if name is empty

type ErrCyclicSchema

type ErrCyclicSchema struct {
	Loop []*jsonschema.Schema
}

func (ErrCyclicSchema) Error

func (e ErrCyclicSchema) Error() string

type ErrDataIngestion

type ErrDataIngestion struct {
	Key string
	Err error
}

func (ErrDataIngestion) Error

func (e ErrDataIngestion) Error() string

func (ErrDataIngestion) Unwrap

func (e ErrDataIngestion) Unwrap() error

type ErrInvalidBooleanValue

type ErrInvalidBooleanValue struct {
	NodeID string
	Value  string
}

func (ErrInvalidBooleanValue) Error

func (e ErrInvalidBooleanValue) Error() string

type ErrInvalidSchema

type ErrInvalidSchema string

func (ErrInvalidSchema) Error

func (e ErrInvalidSchema) Error() string

type ErrSchemaValidation

type ErrSchemaValidation string

func (ErrSchemaValidation) Error

func (e ErrSchemaValidation) Error() string

type ErrValueExpected

type ErrValueExpected struct {
	NodeID string
}

func (ErrValueExpected) Error

func (e ErrValueExpected) Error() string

type ExportOptions

type ExportOptions struct {
	// BuildNodeKeyFunc builds a node key from the node
	BuildNodeKeyFunc func(ls.Node) (string, bool, error)
}

ExportOptions are used to produce the output from the document

func (ExportOptions) BuildNodeKey

func (options ExportOptions) BuildNodeKey(node ls.Node) (string, bool, error)

type ImportedEntity

type ImportedEntity struct {
	Entity CompiledEntity

	Layer *ls.Layer `json:"-"`
}

func CompileAndImport

func CompileAndImport(entities []Entity) ([]ImportedEntity, error)

CompileAndImport compiles the given entities and imports them as layers

func Import

func Import(entities []CompiledEntity) ([]ImportedEntity, error)

Import a JSON schema

A JSON schema may include many object definitions. This import algorithm creates a schema for each entity.

type Ingester

type Ingester struct {
	Schema *ls.Layer

	// This is the schema node property containing the JSON key.
	//
	// If the schema defines KeyTerm: x, then the schema object matches
	// the JSON key x
	KeyTerm string

	// NewNodeFunc will create a new node for the data graph with the
	// given ID. If NewNodeFunc is nil, a ls.BasicDocumentNode will be
	// created. The function should not add the node to the graph.
	NewNodeFunc func(string) ls.Node

	// NewEdgeFunc will create a new edge for the data graph with the
	// given label. If NewEdgeFunc is nil, a ls.Edge will be
	// created. The function should not add the edge to the graph.
	NewEdgeFunc func(string) ls.Edge

	NodeIDGeneratorFunc func(path []interface{}, schemaNode ls.Node) string
}

func (*Ingester) DefaultNodeIDGenerator

func (ingester *Ingester) DefaultNodeIDGenerator(path []interface{}, schemaNode ls.Node) string

DefaultNodeIDGenerator returns Ingester.Schema.ID + join(path,".")

func (*Ingester) Ingest

func (ingester *Ingester) Ingest(target *digraph.Graph, baseID string, input OM) (ls.Node, error)

Ingest a json document using the schema. The output will have all input nodes associated with schema nodes.

BaseID is the ID of the root object. All other attribute names are generated by appending the attribute path to baseID

type KeyValue

type KeyValue struct {
	Key   string
	Value OM
}

KeyValue is a JSON key-value pair

func (KeyValue) Encode

func (e KeyValue) Encode(w io.Writer) error

Encode a key-value pair

type OM

type OM interface {
	Encode(io.Writer) error
}

OM represents the JSON object model that preserves order

func Decode

func Decode(decoder *json.Decoder) (OM, error)

func Export

func Export(node ls.Node, options ExportOptions) (OM, error)

Export the document subtree to the target. The returned result is OM, which respects element ordering

type Object

type Object struct {
	Values []KeyValue
}

Object represents a JSON object

func (Object) Encode

func (e Object) Encode(w io.Writer) error

Encode a json object

type Value

type Value struct {
	Value interface{}
}

Value is a JSON value. It is one of nil, string, bool, json.Number

func (Value) Encode

func (e Value) Encode(w io.Writer) error

Encode a value

Jump to

Keyboard shortcuts

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