jackson-jsonld License Build Status Join the chat at https://gitter.im/io-informatics/jackson-jsonld

JSON-LD Module for Jackson

Install it

If you use maven, just add the dependency to your pom.xml


Use it

The first step is to register the module with jackson.

    // this configure the JsonldModule with an empty default context.
   objectMapper.registerModule(new JsonldModule());

If you want to provide a default JSON-LD context for your application check the other constructors of JsonldModule

Next, we can have annotated java beans which can be serialized using Jsonld. For instance:

    public class Person {
        public  String id;
        public String name;
        public String jobtitle;
        public String url;

Instances of Person can we wrapped inside a JsonldResource or JsonldGraph/HydraCollection. To do this you can use the builders that the library provides:

    Person alex = new Person();
    alex.id = "mailto:[email protected]";
    alex.name = "Alex De Leon";
    alex.jobtitle = "Software Developer";
    alex.url = "http://alexdeleon.name";

    objectMapper.writer().writeValue(System.out, JsonldResource.Builder.create().build(alex));

The above will generate the following JSON-LD representation:

        "@context": {
            "name": "http://schema.org/name",
            "jobtitle": "http://schema.org/jobTitle",
            "url": "http://schema.org/url"
        "@type": "http://schema.org/Person",
        "name": "Alex De Leon",
        "jobtitle": "Software Developer",
        "url": "http://alexdeleon.name",
        "@id": "mailto:[email protected]"