Skip to content

danpape/jsonld-cpp-client

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

7 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

jsonld-cpp-client

This is a simple client application for testing the jsonld-cpp library

Building jsonld-cpp-client

To build jsonld-cpp-client, you will need:

  • cmake
  • g++, clang or Visual Studio (community edition)
  • jsonld-cpp installed locally

jsonld-cpp-client uses a pretty standard cmake build system:

mkdir build
cd build
cmake ..
make

If jsonld-cpp is not installed to a standard location, you will need to provide cmake with a prefix path:

cmake -DCMAKE_PREFIX_PATH=/tmp/jsonld-install ..

Installing prerequisites

If the above build instruction don't work, you probably need to install some prerequisites. For example, on a fresh Debian Bullseye system:

$ sudo apt install make cmake gcc g++

After that, make sure you can build and install jsonld-cpp. See its documentation for more details.

Samples

There are two command line applications included in jsonld-cpp-client and a couple of sample JSON-LD files to use.

> cat ../samples/ex01a.jsonld
{
  "@context": {
    "name": "http://xmlns.com/foaf/0.1/name",
    "isKnownBy": { "@reverse": "http://xmlns.com/foaf/0.1/knows", "@container": "@index" }
  },
  "@id": "http://example.com/people/markus",
  "name": "Markus Lanthaler",
  "isKnownBy": {
    "Dave": {
      "@id": "http://example.com/people/dave",
      "name": "Dave Longley"
    },
    "Gregg": {
      "@id": "http://example.com/people/gregg",
      "name": "Gregg Kellogg"
    }
  }
}
> cat ../samples/ex01b.jsonld
{ "@context": { "name": "http://xmlns.com/foaf/0.1/name", "isKnownBy": { "@reverse": "http://xmlns.com/foaf/0.1/knows", "@container": "@index" } }, "@id": "http://example.com/people/markus", "isKnownBy": { "Dave": { "@id": "http://example.com/people/dave", "name": "Dave Longley" }, "Gregg": { "@id": "http://example.com/people/gregg", "name": "Gregg Kellogg" } }, "name": "Markus Lanthaler" } 

expand-jsonld

expand-jsonld will take a JSON-LD file and run the 'expansion' algorithm. The expanded file will be output to the terminal.

> ./expand-jsonld ../samples/ex01a.jsonld  | jq
[
  {
    "@id": "http://example.com/people/markus",
    "@reverse": {
      "http://xmlns.com/foaf/0.1/knows": [
        {
          "@id": "http://example.com/people/dave",
          "@index": "Dave",
          "http://xmlns.com/foaf/0.1/name": [
            {
              "@value": "Dave Longley"
            }
          ]
        },
        {
          "@id": "http://example.com/people/gregg",
          "@index": "Gregg",
          "http://xmlns.com/foaf/0.1/name": [
            {
              "@value": "Gregg Kellogg"
            }
          ]
        }
      ]
    },
    "http://xmlns.com/foaf/0.1/name": [
      {
        "@value": "Markus Lanthaler"
      }
    ]
  }
]

jsonld2rdf

jsonld2rdf can convert a JSON-LD document into RDF data in NQuads format. This program first runs the 'expansion' algorithm, then converts the JSON-LD to RDF using 'RDF serialization. The RDF data will be output to the terminal.

> ./jsonld2rdf ../samples/ex01a.jsonld
<http://example.com/people/dave> <http://xmlns.com/foaf/0.1/knows> <http://example.com/people/markus> .
<http://example.com/people/dave> <http://xmlns.com/foaf/0.1/name> "Dave Longley" .
<http://example.com/people/gregg> <http://xmlns.com/foaf/0.1/knows> <http://example.com/people/markus> .
<http://example.com/people/gregg> <http://xmlns.com/foaf/0.1/name> "Gregg Kellogg" .
<http://example.com/people/markus> <http://xmlns.com/foaf/0.1/name> "Markus Lanthaler" .

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • C++ 81.9%
  • CMake 18.1%