Click to copy

• Reviewed for ksqlDB 0.29

How to Create Stream from JSON topic in ksqlDB

ksqlDB can parse topics that contain raw JSON data.

Having a topic that looks like t he following:

ksql> PRINT scores_topic FROM BEGINNING;
Value format: JSON or KAFKA_STRING
rowtime: 2022/07/19 10:08:01.864 Z, 
key: <null>, 
value: {"SCORE":3.8,"USER":{"NAME":"Alice","AGE":30}}, 
partition: 3

Use CREATE STREAM statement, specify the structure using ksqlDB types and set the VALUE_FORMAT='JSON':

CREATE STREAM scores_stream (
  score DOUBLE,
  user STRUCT<name STRING, age INT>
) WITH (
  KAFKA_TOPIC = 'scores_topic',
  VALUE_FORMAT = 'JSON'
);
Discover what readers are saying
topictale
Get easy to digest how-tos on ksqlDB
Sign up
Please read our Privacy Policy to understand how we protect and manage your data.
You may also like