DEV Community

Michael
Michael

Posted on • Originally published at gbase8.cn

Loading JSON Data Files in GBase 8a

Starting from version 9.5.3.28, GBase 8a supports loading JSON files directly into tables. By specifying DATA_FORMAT 6 in the LOAD DATA INFILE statement, each JSON object is automatically mapped to table columns. This article covers common JSON loading patterns and important caveats for your gbase database.

Basic Syntax

LOAD DATA INFILE 'file_path' INTO TABLE table_name DATA_FORMAT 6;
Enter fullscreen mode Exit fullscreen mode

Loading Patterns

Single JSON Object (One Row)

{"id":"1","name":"First"}
Enter fullscreen mode Exit fullscreen mode

Loads one row. Column names in the JSON must match the table columns.

One JSON Object Per Line

{"id":"1","name":"First"}
{"id":"2","name":"second no comer between line"}
Enter fullscreen mode Exit fullscreen mode

Each line is treated as an independent record. Trailing commas at the end of lines are optional and safely ignored.

Multiple JSON Objects on a Single Line

  • Compact form (no separator): Objects placed directly next to each other are parsed correctly.

{"id":"1","name":"First"}{"id":"2","name":"second"} → two rows.

  • Comma separated (without array): A comma between objects causes only the first object to load; subsequent objects are skipped.

  • JSON Array: Wrap objects in [...] and separate with commas. All objects in the array are loaded.

[{"id":"1","name":"First"},{"id":"2","name":"second"}] → two rows.

Mixed‑Format Files

You can combine lines with single objects, compact objects, and arrays in the same file. The parser handles each line independently.

Important Limitations

  • No nested JSON values: A column value cannot be another JSON object or array. The structure must be flat.
  • File splitting restrictions: If the JSON data is compact (no delimiters between objects) or the values themselves contain the line terminator, the file cannot be split across multiple loader processes. In such cases the entire file is processed as a single unit, which bypasses the per‑line length limit but requires the entire content to be syntactically perfect.
  • Literal constants: JSON keywords true, false, and null must be written in lowercase and must not be enclosed in double quotes. Any deviation will cause a parsing error.

JSON loading in a gbase database makes ingesting semi‑structured data straightforward. By following these patterns, you can seamlessly integrate JSON log streams, IoT data, or API responses into your GBASE analytical pipelines without external preprocessing.

Top comments (0)