Documentation
¶
Overview ¶
Package jsonld contains utility types and functions to handle JSON-LD files.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Context ¶
type Context struct {
// contains filtered or unexported fields
}
Context is a JSON-LD @context entry. In JSON-LD this can be a string, a list of strings, a map containing either strings or objects.
func NewNamedContext ¶
func NewNamedContext(c map[string]ContextEntry) Context
NewNamedContext creates a new context from the given map.
func NewRootContext ¶
func NewRootContext(c []ContextEntry) Context
NewRootContext creates a new context from the given list. Do note that any `Type` properties will be lost.
func (*Context) GetContextsFor ¶
func (c *Context) GetContextsFor(ns string) []ContextEntry
GetContextsFor looks up the namespace/element by name and return the relevant contexts for it. If there are any named contexts, it returns those, else it returns the root contexts.
func (*Context) GetRootContexts ¶
func (c *Context) GetRootContexts() []ContextEntry
GetRootContexts returns the root contexts, this can be empty if there are named contexts.
func (Context) MarshalJSON ¶
MarshalJSON will first check if namedContext are available, and marshal those if they are. If they are not, it will check if there's only a single rootContext and marshal that as a string, else it will marshal the entire rootContexts list.
func (*Context) UnmarshalJSON ¶
UnmarshalJSON will first try to unmarshal the context as a map of ContextEntry structs, if that fails, it will try to unmarshal it as a list of strings, and if that fails, as a single string.
type ContextEntry ¶
ContextEntry is a JSON-LD context entry.
func (ContextEntry) MarshalJSON ¶
func (ce ContextEntry) MarshalJSON() ([]byte, error)
MarshalJSON will marshal the ContextEntry as an object if Type is not empty, and as a string containing just the ID if Type is empty.
func (*ContextEntry) UnmarshalJSON ¶
func (ce *ContextEntry) UnmarshalJSON(data []byte) error
UnmarshalJSON unmarshals a context entry. It first tries to unmarshal an entry as an object, and if that fails, it will try to unmarshal it as a string. If that succeeds, it will assign that string to the `ID` field.