Reading JSON Objects

Estimated reading time: 1 minute

OT Link Platform DataHub sends messages in JSON format. You can parse JSON messages to pick out and manipulate certain pieces of data with Function nodes.

Create the Flow

To parse a JSON object in a message payload from a topic on OT Link Platform:

  1. Connect a DataHub Subscribe node, a Function node, and a Debug node. Below is a picture of the final result:

  2. In OT Link Platform, click DeviceHub > Tags.
  3. Click onĀ  next to an existing tag to copy a Raw Topic. Add a tag if there are none.

  4. In Flows, double-click the DataHub node and paste the copied topic.
  5. Double-click the function node. Enter the following lines of code:

    var obj = JSON.parse(msg.payload); // Stores JSON text as an object.
    var temp = JSON.stringify(obj.registerId); // Gets the registerId from our object and makes it a string.
    msg.payload = temp; // Assigns the registerId string to our output message payload string.
    return msg;
    
  6. Click Done and Save the flow.

  7. Click the debug tab at the bottom of the flow screen to view the output.