theThingBox

Add semantic to the Node-RED msg payload with JSON-LD

Posted on Updated on

In the NODE-Red ecosystem, many nodes are built and published.
When someone creates a node that produces geo coordinates (this is an example), and another a node that consumes geo coordinates, it is very important that these two nodes can be linked together in NODE-Red. To achieve that, the former should produce a payload that the latter can read.

Using JSON or msg is not enough:

{
 "latitude" : "40.75",
 "longitude" : "73.98"
 }

Also consider another example:

{
"temperature" : "40"
}

What does it refer to? degrees Celsius or Fahrenheit?

We must agree on the content of the JSON object in the payload.

TheThingBox choice

In the ThingBox project (theThingbox.io) we decided to use JSON-LD to format the payload.

JSON-LD allows to uniquely define the content of a JSON object.

{
 "@type" : "http://schema.org/GeoCoordinates",
 "http://schema.org/latitude" : "40.75",
 "http://schema.org/longitude" : "73.98"
 }

When a node finds an object containing:

"@type" : "http://schema.org/GeoCoordinates"

then the semantic of the object is uniquely defined.

The members are also uniquely defined.

The previous object can be “compacted” by factoring paths into a context:

{
 "@context": "http://schema.org",
 "@type": "GeoCoordinates",
 "latitude": "40.75",
 "longitude": "73.98"
 }

Many objects are already defined in schema.org.
Find more about JSON-LD at http://json-ld.org  and use it in Nodes!