https://www.automationdirect.com/brx
(VID-BRX-0030)
This video is part 1 of a 3 part series that details the needed information to setup and use JSON in the do-more BRX PLC.
This video details the basic information needed for implementation of JSON in the Do-more BRX PLC.
Our FREE Practical Guide to Programmable Logic Controllers eBook: https://www.automationdirect.com/ebooks/plc-handbook
This is a short training video on the JSON data format. JSON stands for JavaScript Object Notation and is a set of rules or syntax on how to format data in text for exchange via some communication protocol. It was designed with JavaScript in mind, so when exchanging data between, say, a browser and a server, the data, being only text, can be easily converted back and forth from and to JavaScript objects. Now that all may sound a bit too much for someone who is not a JavaScript programmer, so what does this mean for the rest of us who are not JavaScript programmers? What does this mean in the BRX plc world? Well, for example, JSON data format is commonly used in the popular MQTT IoT protocol, which BRX plc support. In MQTT, there can be many devices exchanging data with one another via the broker, and all these various devices can publish their data to the broker in any form they choose; however, if that data is to be easily understood, then they could use the JSON as a data format and since JSON always is in text and it's self-describing, that is it's easy to read, then the subscribers can more readily understand and view this data thus no JavaScript knowledge or skills are needed to use the JSON data. Another growing field of data sharing is called Rest API. Rest stands for representational state transfer, and API stands for application programming interface again; you don't have to know this, but it's good to know that a BRX plc can query a data source, in this case, a Rest API on the internet, gather data - an example is a Weather API say at API.openweathermap.org. The BRX plc can use an HTML instruction and execute what's called an HTML GET and query this weather API on the internet. The Weather API will respond with the data that is in JSON data format and as you can see in this data, you can gather all kinds of information about the weather if you know what you're looking for. So once again, you don't really have to know all the ins and outs of a Rest API to use them, but you will have to know how to utilize a JSON data, so let's get to that, All JSON text data is either an object or an array. Curly braces hold objects; square brackets hold arrays. JSON objects contain name/value pairs. Here you see the name is "FieldName" and the value is "Value." Name/value pairs are separated by a colon here highlighted in red. Objects can contain multiple name/value pairs. These are separated by commas. This object contains three name/value pairs. The name portion of a name/value pair is always a string and it's contained in double-quotes, as shown. In this example, the value is also a string, so it's contained in double-quotes as well. But regarding the value, it doesn't have to be a string. In fact there are six types of values in JSON – strings, numbers, another JSON object, arrays, Booleans, and nulls. The first one is a string. As we have already seen, a string value type is contained in double-quotes. In this example, the name is "City" and the value is the string, "Cairns". The second value type is a number. Numbers can be integers or reals. Here you see the name is "Age" and its value is an integer, 30. Here you see the name is "Latitude" and its value is -16.92. The third value type is another JSON object. JSON objects can be nested as deep as needed. There's no theoretical limit to how deep. As per every JSON object, nested objects are also contained inside curly braces. Notice here that the name is "Client" and the value of client is another JSON object in curly braces. It contains three name/value pairs - name, age, and city - each with their respective values. The fourth value type is a JSON array. Arrays are contained inside square brackets, as mentioned earlier and the values are separated by commas. Notice in the first example the JSON object has a name, “Clients” but the value of Clients is an array of strings - “John”, “Anna”, and “Peter”. In the second example the JSON object's name is “Temperatures” and its value contains an array of integers. The fifth value type is Boolean that is a name that can have a value of true or false. Thus the name/value pair in this example has a name of “Sale” and a Boolean value of true. And notice the true is not contained in quotes. Just like number, Booleans are not contained in quotes. The sixth and final value type is null. Just like numbers and Boolean types, the JSON null doesn't have quotes around it. A JSON record, as you can see, can get quite complex in its nested objects and arrays. So much so that it can be very difficult to read or sort out the contained data into pieces so that it makes sense. Notice this one. You can see by the multiple curly braces and square brackets that the data is nested. It is for this reason that a display format commonly called JSON Pretty was invented. JSON Pretty display format doesn't change the data at all, but it merely rearranges it into a more readable form. It takes this messy string data and displays it like this. So, now you can see the arrays and nested objects much easier and pick out what you want. Support for JSON data format was introduced in Do-more technology version 2.5.2 in April of 2019. Instructions were added for both building and parsing of JSON records; these are the JSON build for building your own record in JSON format and JSON parse for interpreting a record you receive in this format. Version 2.7.4 came out in April of 2020. This added a tool for viewing JSON data in a Pretty format. Here, you see the data record in a single string that is difficult to read, and the new tool allows you to view the JSON data string in such a way that it's easy to view and pick out what you're interested in. Now this concludes the introduction to JSON data format. The next video shows how to use JSON build instructions to create your own JSON data record. Thanks for watching.
Voted #1 mid-sized employer in Atlanta
Check out our
job openings