Get Started Free
‹ Back to courses
course: ksqlDB 101

Hands On: Converting Data Formats with ksqlDB

2 min
Allison

Allison Walther

Integration Architect (Presenter)

Hands On: Converting Data Formats with ksqlDB

This exercise will teach you how to change data formats in ksqlDB.

Inspect Your Existing Data

  1. Begin by printing your orders_flat stream from Hands On: Flatten Nested Records with ksqlDB to show the existing JSON data:

    PRINT orders_flat FROM BEGINNING;

    Click Run query.

  2. Stop the query. Then expand a record to see the JSON structure.

Change Your Data's Format and Inspect It Again

  1. Enter a CREATE STREAM AS statement, with VALUE_FORMAT set to delimited:

    CREATE STREAM orders_csv
    WITH(VALUE_FORMAT='delimited', KAFKA_TOPIC='orders_csv') AS
    SELECT * FROM orders_flat EMIT CHANGES;

    Click Run query. This will help to clean up the JSON you saw in Step 2.

  2. Run a PRINT statement to see your newly delimited data:

    PRINT orders_csv FROM BEGINNING;

    Click Run query, then scroll down and expand a record to see the comma-delimited fields.

    It's as easy as that: VALUE_FORMAT helps you to change formats within ksqlDB.

Use the promo code KSQLDB101 & CONFLUENTDEV1 to get $25 of free Confluent Cloud usage and skip credit card entry.

Be the first to get updates and new content

We will only share developer content and updates, including notifications when new content is added. We will never send you sales emails. 🙂 By subscribing, you understand we will process your personal information in accordance with our Privacy Statement.

Hands On: Converting Data Formats with ksqlDB

In this exercise, we'll work with changing data formats. The first thing that we're gonna want to do is print out this orders_flat stream to show the existing JSON data. KsqlDB formats it pretty poorly. Let's expand a record to see the JSON structure. Go ahead and enter a create stream as statement with the value format specified to delimit it. This will help clean up that JSON structure we saw earlier. Run the query. Now let's run a print orders_CSV statement to show our newly delimited data. Again, scroll down and expand a record to show the comma-delimited fields. And it's as easy as that. Value format helps you change between different formats within ksqlDB.