JSON
1 min read
On this page
This article introduces you to the usage and type mapping of the JSON format.
Background Information
JSON format can read and write JSON data based on the JSON structure. Currently, the JSON structure is automatically deduced from the table structure.
Example of Use
An example of constructing a table using Kafka and JSON format is as follows.
SQL
1 CREATE TABLE user_behavior (
2 user_id BIGINT,
3 item_id BIGINT,
4 category_id BIGINT,
5 behavior STRING,
6 ts TIMESTAMP(3)
7 ) WITH (
8 'connector' = 'kafka',
9 'topic' = 'user_behavior',
10 'properties.bootstrap.servers' = 'localhost :9092',
11 'properties.group.id' = 'testGroup',
12 'format' = 'json',
13 'json.fail-on-missing-field' = 'false',
14 'json.ignore-parse-errors' = 'true'
15 );Cofiguration Option
Type Mapping
Currently, the JSON structure will be automatically deduced from the table structure. In Flink, the JSON format uses the jackson databind API (jackson databind API) to parse and generate JSON. The mapping relationship between Flink and JSON data types is as follows.
Other Instructions for Use
For writing to object storage S3, currently it does not support writing files in JSON format. For specific reasons, see FLINK-30635 .
Was this helpful?