Skip to content

Commit

Permalink
Merge pull request #143 from Tedoshiii/teodor-fourth-tutorial
Browse files Browse the repository at this point in the history
Second and Fourth Tutorial Feedback Application
  • Loading branch information
egekorkan authored Mar 15, 2024
2 parents f9be93d + b2f2115 commit a414420
Show file tree
Hide file tree
Showing 6 changed files with 68 additions and 68 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ Let's continue with the parcel truck example. In that example, the header would

This is what an HTTP header can look like. A header can contain information like request context, response context, status and it can indicate payload type.

There are different payload types such as JSON, XML, CBOR TextAudio and video and more.
There are different payload types such as JSON, XML, CBOR, Text,Audio and Video and more.

So let us show you an example of JSON payload.
This is a temperature payload, a single number.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,54 +60,54 @@ This is what an HTTP header can look like. A header can contain
00:01:51.543 --> 00:01:58.069
information like request context, response context, status and it can indicate payload type.

00:01:58.069 --> 00:02:12.466
There are different payload types such as JSON, XML, CBOR TextAudio and video and more.
00:01:58.069 --> 00:02:11.883
There are different payload types such as JSON, XML, CBOR, Text,Audio and Video and more.

00:02:12.466 --> 00:02:16.160
00:02:11.883 --> 00:02:15.577
So let us show you an example of JSON payload.

00:02:16.160 --> 00:02:20.093
00:02:15.577 --> 00:02:19.509
This is a temperature payload, a single number.

00:02:20.093 --> 00:02:23.382
00:02:19.509 --> 00:02:22.798
And this is a configuration payload.

00:02:23.382 --> 00:02:30.148
00:02:22.798 --> 00:02:29.564
It is a JSON object consisting of key value pairs desiredUnit and updateInterval. .

00:02:30.148 --> 00:02:36.532
00:02:29.564 --> 00:02:35.949
The temperature payload is sent from the sensor and the configuration is sent to the sensor.

00:02:36.532 --> 00:02:41.737
00:02:35.949 --> 00:02:41.153
In the next video series, we will talk in detail, about

00:02:41.737 --> 00:02:46.942
00:02:41.153 --> 00:02:46.358
JSON. But first let us explain why is JSON so important?

00:02:46.942 --> 00:02:53.253
00:02:46.358 --> 00:02:52.670
Because JSON is very relevant in the scope of the Web of Things, payloads

00:02:53.253 --> 00:02:59.565
00:02:52.670 --> 00:02:58.981
are preferred mostly in JSON. Also, many other API and configuration files use JSON.

00:02:59.565 --> 00:03:05.924
00:02:58.981 --> 00:03:05.340
It is light-weight compared to XML and human readable compared to CBOR. You can see

00:03:05.924 --> 00:03:12.283
00:03:05.340 --> 00:03:11.699
the difference in the representation of the same data in JSON, XML, and CBOR.

00:03:12.283 --> 00:03:17.273
00:03:11.699 --> 00:03:16.689
It is well-established and has a schema language called JSON Schema.

00:03:17.273 --> 00:03:22.263
00:03:16.689 --> 00:03:21.680
It can be used to describe and validate JSON data.

00:03:22.263 --> 00:03:28.022
00:03:21.680 --> 00:03:27.438
Here, you can see an example of a TD in JSON format. We will

00:03:28.022 --> 00:03:33.780
00:03:27.438 --> 00:03:33.196
go later into the details of how a TD should be structured and understood.

00:03:33.780 --> 00:03:39.832
00:03:33.196 --> 00:03:39.248
You can proceed to the next tutorial by clicking on the card or the video description.

Binary file modified Tutorials/whatiswot/4-JSON_in_Practice/4-JSON_in_Practice.mp4
Binary file not shown.
Binary file modified Tutorials/whatiswot/4-JSON_in_Practice/4-JSON_in_Practice.pptx
Binary file not shown.
8 changes: 4 additions & 4 deletions Tutorials/whatiswot/4-JSON_in_Practice/4-JSON_in_Practice.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ Arrays with items of different types are also allowed.

Nested objects are allowed in JSON. “measurement” keyword is an example of this.
Objects start and end with curly brackets. It is basically defining keywords and mapping these keywords to values.
In this example, we define the name and value pairs to describe the data sent by sensors.
In this example, we define the name and value pairs to describe the data sent by sensors.

There is a JSON array of JSON Objects which means all items are JSON objects in that array.

Expand All @@ -16,11 +16,11 @@ Space is a character too.
So “is Active” is not the same as “is Active blank”

Also, JSON is case sensitive. Thus, "is Active" with upper case A is not the same as “is active” with lower case A.
Paying attention to this is important to make sure that object assignments and comparisons work.
Paying attention to this is important to make sure that object assignments and comparisons work.

Lets continue with the mistakes about quotation marks.
Forgetting quotation marks is wrong, it will show validation errors everywhere.
Also putting them when you should not cause unwanted results.
Forgetting quotation marks is wrong, it will show syntax errors everywhere.
Also putting them when you should not, causes unwanted results.
For example → “name”:”true” is not the same as “name”:true without quotation marks.
The first one is not a boolean but a string so it will be interpreted as a string.
The same problem happens with numbers too.
Expand Down
90 changes: 45 additions & 45 deletions Tutorials/whatiswot/4-JSON_in_Practice/4-JSON_in_Practice.vtt
Original file line number Diff line number Diff line change
Expand Up @@ -21,132 +21,132 @@ Nested objects are allowed in JSON. “measurement” keyword is an example of t
00:00:35.624 --> 00:00:44.020
Objects start and end with curly brackets. It is basically defining keywords and mapping these keywords to values.

00:00:44.020 --> 00:00:50.818
00:00:44.020 --> 00:00:51.154
In this example, we define the name and value pairs to describe the data sent by sensors.

00:00:50.818 --> 00:00:59.031
00:00:51.154 --> 00:00:59.366
There is a JSON array of JSON Objects which means all items are JSON objects in that array.

00:00:59.031 --> 00:01:04.981
00:00:59.366 --> 00:01:05.316
Now we will talk about common mistakes while writing JSON files.

00:01:04.981 --> 00:01:09.093
00:01:05.316 --> 00:01:09.429
Let's start with the space character which is frequently overlooked.

00:01:09.093 --> 00:01:11.131
00:01:09.429 --> 00:01:11.466
Space is a character too.

00:01:11.131 --> 00:01:15.543
00:01:11.466 --> 00:01:15.304
So “is Active” is not the same as “is Active blank”

00:01:15.543 --> 00:01:20.257
00:01:15.304 --> 00:01:20.017
Also, JSON is case sensitive. Thus, "is Active" with upper case A

00:01:20.257 --> 00:01:24.971
00:01:20.017 --> 00:01:24.731
is not the same as “is active” with lower case A.

00:01:24.971 --> 00:01:31.224
00:01:24.731 --> 00:01:30.372
Paying attention to this is important to make sure that object assignments and comparisons work.

00:01:31.224 --> 00:01:35.749
00:01:30.372 --> 00:01:34.534
Lets continue with the mistakes about quotation marks.

00:01:35.749 --> 00:01:41.624
Forgetting quotation marks is wrong, it will show validation errors everywhere.
00:01:34.534 --> 00:01:39.984
Forgetting quotation marks is wrong, it will show syntax errors everywhere.

00:01:41.624 --> 00:01:46.162
Also putting them when you should not cause unwanted results.
00:01:39.984 --> 00:01:44.909
Also putting them when you should not, causes unwanted results.

00:01:46.162 --> 00:01:52.662
00:01:44.909 --> 00:01:51.409
For example → “name”:”true” is not the same as “name”:true without quotation marks.

00:01:52.662 --> 00:01:58.012
00:01:51.409 --> 00:01:56.622
The first one is not a boolean but a string so it will be interpreted as a string.

00:01:58.012 --> 00:02:01.637
00:01:56.622 --> 00:01:59.497
The same problem happens with numbers too.

00:02:01.637 --> 00:02:08.137
00:01:59.497 --> 00:02:05.997
This way, the types will be incorrectly interpreted by your programming language.

00:02:08.137 --> 00:02:16.537
00:02:05.997 --> 00:02:13.372
Putting comments inside JSON documents is not valid.

00:02:16.537 --> 00:02:20.172
00:02:13.372 --> 00:02:17.007
Commas should not be used at the final name-value pair.

00:02:20.172 --> 00:02:24.453
00:02:17.007 --> 00:02:21.288
That is why the first one is not valid but difficult to see if

00:02:24.453 --> 00:02:28.735
00:02:21.288 --> 00:02:25.570
you are using it inside of a javascript editor rather than a JSON editor.

00:02:28.735 --> 00:02:35.413
00:02:25.570 --> 00:02:32.248
Similar to the previous one depending on the programming language that you use, syntax might differ.

00:02:35.413 --> 00:02:41.855
00:02:32.248 --> 00:02:38.690
Since JSON will be the object of that programming language before it is parsed and serialized as JSON.

00:02:41.855 --> 00:02:47.306
00:02:38.690 --> 00:02:44.141
For example, in JSON key-value pairs have to be with quotation marks whereas

00:02:47.306 --> 00:02:52.756
00:02:44.141 --> 00:02:49.591
in JavaScript files it is not necessary to have quotation marks, both work.

00:02:52.756 --> 00:02:56.093
00:02:49.591 --> 00:02:52.928
The syntax of the keywords might differ as well.

00:02:56.093 --> 00:03:01.982
00:02:52.928 --> 00:02:58.817
For example, true false keywords in JSON, Rust, JavaScript, and Golang are written lowercase,

00:03:01.982 --> 00:03:07.871
00:02:58.817 --> 00:03:04.706
while in Python the first letter of these keywords needs to be capitalized.

00:03:07.871 --> 00:03:14.208
00:03:04.706 --> 00:03:11.043
Similar to the previous one, the null keyword differs in JSON and Python.

00:03:14.208 --> 00:03:18.436
00:03:11.043 --> 00:03:15.271
In JSON and JavaScript it is null with lowercase while in

00:03:18.436 --> 00:03:22.664
00:03:15.271 --> 00:03:19.499
Python, the same meaning is given with the "None" keyword.

00:03:22.664 --> 00:03:27.561
00:03:19.499 --> 00:03:24.396
Open a code editor. In this example, we used VS Code.

00:03:27.561 --> 00:03:34.112
00:03:24.396 --> 00:03:30.947
Write a JSON file of your choice and save it by giving a file name and adding a .json extension.

00:03:34.112 --> 00:03:38.379
00:03:30.947 --> 00:03:35.214
Then the editor will recognize the file as a JSON document.

00:03:38.379 --> 00:03:45.073
00:03:35.214 --> 00:03:41.908
Now we will read a JSON file from the file system using a JSON library in Python.

00:03:45.073 --> 00:03:51.541
00:03:41.908 --> 00:03:48.376
We open the JSON file that we have previously saved to the file system with open-as-file key words.

00:03:51.541 --> 00:03:56.808
00:03:48.376 --> 00:03:53.643
Then, we can load that JSON file with the load function into the data object.

00:03:56.808 --> 00:04:00.502
00:03:53.643 --> 00:03:57.337
We can also print it to see what is inside the JSON file.

00:04:00.502 --> 00:04:07.201
00:03:57.337 --> 00:04:02.675
Printing the data object in console can look like this.

00:04:07.201 --> 00:04:12.673
00:04:02.675 --> 00:04:08.146
There are many ways to send a JSON file via different protocols, one of

00:04:12.673 --> 00:04:18.145
00:04:08.146 --> 00:04:13.618
them is using Python and its request library for sending an HTTP request.

00:04:18.145 --> 00:04:25.947
00:04:13.618 --> 00:04:21.420
With this library, you can use the post function to send an HTTP POST request with a JSON Payload.

00:04:25.947 --> 00:04:31.332
00:04:21.420 --> 00:04:26.805
As a parameter, it takes the URL to send to and the JSON object.

00:04:31.332 --> 00:04:36.955
00:04:26.805 --> 00:04:32.428
You can proceed to the next tutorial by clicking on the card or the video description.

0 comments on commit a414420

Please sign in to comment.