Documentation ¶
Overview ¶
Package jsonld implements JSON-LD, as defined in https://www.w3.org/TR/json-ld/.
Index ¶
- func Marshal(v interface{}) ([]byte, error)
- func MarshalWithContext(v interface{}, ctx *Context) ([]byte, error)
- func Unmarshal(b []byte, v interface{}) error
- func UnmarshalWithContext(b []byte, v interface{}, ctx *Context) error
- type Context
- type Decoder
- type Encoder
- type FetchContextFunc
- type Props
- type Resource
- type Type
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Marshal ¶
Marshal returns the JSON-LD encoding of v.
Marshal uses the same rules as the encoding/json package, except for Resource values.
func MarshalWithContext ¶
MarshalWithContext returns the JSON-LD encoding of v with the context ctx.
func Unmarshal ¶
Unmarshal parses the JSON-LD-encoded data and stores the result in the value pointed to by v.
Unmarshal uses the inverse of the encodings that Marshal uses, allocating maps, slices, and pointers as necessary, with the following additional rules:
To unmarshal JSON-LD into a struct:
- If the struct has a field named JSONLDType of type Type, Unmarshal records the resource type in that field.
- If the JSONLDType field has an associated tag of the form "type-URI", the resource must have the given type or else Unmarshal returns an error.
- If the struct has a field whose tag is "@id", Unmarshal records the resource URI in that field.
- If the resource has a property whose URI matches a tag formatted as "property-URI", the property value is recorded in that field.
To unmarshal JSON-LD into an interface value, Unmarshal uses the same rules as the encoding/json package, except for resources which are stored as *Resource.
func UnmarshalWithContext ¶
UnmarshalWithContext parses the JSON-LD-encoded data with the context ctx and stores the result in the value pointed to by v.
Types ¶
type Context ¶
type Context struct { URL string Lang string Base string // Base URI to resolve relative URIs. Vocab string // Base vocabulary. Terms map[string]*Resource }
func FetchContext ¶
FetchContext fetches remote contexts with http.DefaultClient.
type Decoder ¶
type Decoder struct { // Context, if non-nil, will be used when decoding values. Context *Context // FetchContext, if non-nil, will be called to fetch remote contexts. By // default, remote contexts are not fetched. FetchContext FetchContextFunc // contains filtered or unexported fields }
Decoder decodes JSON-LD values.
type Encoder ¶
type Encoder struct { // If specified, this context will be used when encoding values. Context *Context // contains filtered or unexported fields }
Encoder encodes JSON-LD values.
type FetchContextFunc ¶
FetchContextFunc fetches remote contexts.