0
0
IOT Protocolsdevops~10 mins

JSON for human-readable data in IOT Protocols - Step-by-Step Execution

Choose your learning style9 modes available
Process Flow - JSON for human-readable data
Start with data
Convert data to JSON format
Format JSON with indentation
Output human-readable JSON
Use JSON in IoT communication
Data is converted into JSON format, then formatted with spaces and line breaks to make it easy to read before sending or storing.
Execution Sample
IOT Protocols
import json
data = {"temp": 22, "status": "ok"}
json_str = json.dumps(data, indent=2)
print(json_str)
This code converts a Python dictionary to a nicely formatted JSON string for easy reading.
Process Table
StepActionInputOutput
1Define data dictionary{"temp": 22, "status": "ok"}data variable holds dictionary
2Convert to JSON string with indentdata dictionary{ "temp": 22, "status": "ok" }
3Print JSON stringJSON stringPrinted human-readable JSON on screen
4EndN/AProcess complete
💡 All steps done, JSON string is human-readable and printed
Status Tracker
VariableStartAfter Step 1After Step 2Final
dataundefined{"temp": 22, "status": "ok"}{"temp": 22, "status": "ok"}{"temp": 22, "status": "ok"}
json_strundefinedundefined{ "temp": 22, "status": "ok" }{ "temp": 22, "status": "ok" }
Key Moments - 2 Insights
Why do we use indent in json.dumps?
Indent adds spaces and line breaks to JSON output making it easier to read, as shown in step 2 of the execution_table.
Is the original data changed when converting to JSON string?
No, the original data dictionary stays the same; json.dumps creates a new string without modifying the data (see variable_tracker).
Visual Quiz - 3 Questions
Test your understanding
Look at the execution_table, what is the output after step 2?
A{ "temp": 22, "status": "ok" }
B{"temp":22,"status":"ok"}
Cdata variable holds dictionary
DPrinted human-readable JSON on screen
💡 Hint
Check the Output column in row with Step 2 in execution_table
At which step is the JSON string printed?
AStep 1
BStep 3
CStep 2
DStep 4
💡 Hint
Look at the Action column in execution_table for printing action
If we remove indent from json.dumps, how would the output change?
AOriginal data dictionary would change
BJSON string would be more readable with extra spaces
CJSON string would be compact without spaces or line breaks
DJSON string would not be created
💡 Hint
Refer to key_moments about indent effect and step 2 output
Concept Snapshot
JSON converts data into text format.
Use json.dumps(data, indent=2) for readable output.
Indent adds spaces and new lines.
Original data stays unchanged.
Readable JSON helps debugging and communication.
Full Transcript
This lesson shows how to convert data into human-readable JSON format. We start with a data dictionary containing temperature and status. Using json.dumps with indent=2, we create a JSON string with spaces and line breaks. This string is printed to the screen. The original data remains unchanged. Indentation makes JSON easier to read for humans, which is helpful in IoT communication and debugging.