0
0
Kafkadevops~10 mins

Serialization (String, JSON, Avro) in Kafka - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to serialize a string message before sending it to Kafka.

Kafka
producer.send(topic, value=[1].encode('utf-8'))
Drag options to blanks, or click blank then click option'
Astr(message)
Bjson.dumps(message)
Cmessage
Dbytes(message)
Attempts:
3 left
💡 Hint
Common Mistakes
Trying to send the message without encoding it.
Using json.dumps on a plain string.
2fill in blank
medium

Complete the code to serialize a Python dictionary to JSON string before sending.

Kafka
producer.send(topic, value=[1].encode('utf-8'))
Drag options to blanks, or click blank then click option'
Ajson.dumps(data)
Bdata
Cstr(data)
Dpickle.dumps(data)
Attempts:
3 left
💡 Hint
Common Mistakes
Using str() which does not produce valid JSON.
Sending the dict directly without serialization.
3fill in blank
hard

Fix the error in deserializing a JSON message received from Kafka.

Kafka
data = json.loads(message.[1]('utf-8'))
Drag options to blanks, or click blank then click option'
Aencode
Bto_bytes
Cto_str
Ddecode
Attempts:
3 left
💡 Hint
Common Mistakes
Using encode instead of decode causes errors.
Trying to load JSON directly from bytes.
4fill in blank
hard

Fill both blanks to create a dictionary comprehension that serializes only keys with length greater than 3 to JSON strings.

Kafka
result = {key: json.dumps(value) for key, value in data.items() if len(key) [1] 3 and key [2] 'id'}
Drag options to blanks, or click blank then click option'
A>
B<
C!=
D==
Attempts:
3 left
💡 Hint
Common Mistakes
Using '<' instead of '>' for length comparison.
Using '==' instead of '!=' to exclude keys.
5fill in blank
hard

Fill all three blanks to create a dictionary comprehension that serializes keys in uppercase, values only if they are integers, and filters values greater than 10.

Kafka
result = [1]: [2] for [3], v in data.items() if isinstance(v, int) and v > 10}
Drag options to blanks, or click blank then click option'
Ak.upper()
Bv
Ck
Djson.dumps(v)
Attempts:
3 left
💡 Hint
Common Mistakes
Using v directly without serialization.
Using wrong variable names for keys.