Skip to content

Package jsonld provides JSON-LD encoders and decoders, for the Go programming language. And in particular, handles the way the Fediverse, ActivityPub, and ActivityStreams uses JSON-LD.

License

Notifications You must be signed in to change notification settings

reiver/go-jsonld

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

76 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

go-jsonld

Package jsonld provides JSON-LD encoders and decoders, for the Go programming language.

And in particular, handles the way the Fediverse, ActivityPub, and ActivityStreams uses JSON-LD.

And import thing to understand is — you use separate Go structs to represent each JSON-LD namespace. Both for marshaling and unmarshaling.

Documention

Online documentation, which includes examples, can be found at: http://godoc.org/github.com/reiver/go-jsonld

GoDoc

Example

Here is a simple example with only one JSON-LD namespace:

import "github.com/reiver/go-jsonld"

// ...

// Note that "jsonld" struct-tags are used on the first 2 fields,
// and "json" struct-tags are used on the rest of the fields.
type MyStruct struct {
	NameSpace jsonld.NameSpace `jsonld:"http://example.com/ns"`
	Prefix    jsonld.Prefix    `jsonld:"ex"`

	Once   bool   `json:"once"`
	Twice  int    `json:"twice"`
	Thrice string `json:"thrice,omitempty"`
	Fource uint   `json:"fource"`
}

// ...

var value MyStruct // = ...

bytes, err := jsonld.Marshal(value)

Here is a more typical example with multiple JSON-LD namespaces.

import "github.com/reiver/go-jsonld"

// ...

type Person struct {
	NameSpace jsonld.NameSpace `jsonld:"http://ns.example/person"`
	Prefix    jsonld.Prefix    `jsonld:"person"`

	GivenName         string `json:"given-name,omitempty"`
	AdditionalNames []string `json:"additional-names,omitempty"`
	FamilyName        string `json:"family-name,omitempty"`
}

type Programmer struct {
	NameSpace jsonld.NameSpace `jsonld:"http://example.com/programmer"`
	Prefix    jsonld.Prefix    `jsonld:"programmer"`

	ProgrammingLanguage string `json:"programming-language,omitempty"`
}

// ...

var person Person // = ...
var programmer Programmer // = ...

bytes, err := jsonld.Marshal(person, programmer)

Import

To import package jsonld use import code like the follownig:

import "github.com/reiver/go-jsonld"

Installation

To install package jsonld do the following:

GOPROXY=direct go get github.com/reiver/go-jsonld

Author

Package jsonld was written by Charles Iliya Krempeaux

About

Package jsonld provides JSON-LD encoders and decoders, for the Go programming language. And in particular, handles the way the Fediverse, ActivityPub, and ActivityStreams uses JSON-LD.

Topics

Resources

License

Stars

Watchers

Forks

Languages