Lindorm Cassandra Query Language (CQL) supports JSON in SELECT and INSERT statements. JSON support doesn't change the core API — you still define a schema for your database. It simply gives you a way to read and write column data as JSON.
SELECT JSON
Add the JSON keyword to a SELECT statement to return each row as a JSON-encoded map. The rest of the SELECT behavior stays the same.
The map keys match the column names in a regular result set. For example, you can execute the SELECT JSON a, b FROM ... statement to generate a map that contains the a and b keys.
INSERT JSON
Add the JSON keyword to an INSERT statement to insert a JSON-encoded map as a row. The JSON map format must match what SELECT JSON returns for the same table.
Wrap case-sensitive column names in double quotation marks.
For example, you can execute the following statement to insert a map into a table that contains the key and value columns:
INSERT INTO persioninfo JSON '{ "c1": "key", "c2": "value"}'By default, columns omitted from the JSON map are set to NULL. This rule also applies when the default value NULL is explicitly specified, which means that all existing values of the unspecified columns are removed.
JSON encoding of CQL data types
The following table shows how Lindorm CQL maps CQL data types to and from JSON. It describes the data types accepted in INSERT JSON statements and fromJson() functions, and the data types returned for SELECT JSON statements and toJson() functions.
| CQL type | Accepted JSON input | Returned JSON format | Notes |
|---|---|---|---|
ascii | string | string | Uses \u JSON escape sequences |
bigint | integer, string | integer | String must be a valid 64-bit integer |
blob | string | string | String must be 0x followed by an even number of hexadecimal digits |
boolean | boolean, string | boolean | Valid string values: "true" and "false" |
date | string | string | Format: YYYY-MM-DD (UTC) |
decimal | integer, float, string | float | May exceed 32-bit or 64-bit IEEE-754 floating-point precision |
double | integer, float, string | float | String must be a valid integer or floating-point number |
float | integer, float, string | float | String must be a valid integer or floating-point number |
inet | string | string | IPv4 or IPv6 address |
int | integer, string | integer | String must be a valid 32-bit integer |
smallint | integer, string | integer | String must be a valid 16-bit integer |
text | string | string | Uses \u JSON escape sequences |
time | string | string | Format: HH-MM-SS[.fffffffff] |
timestamp | integer, string | string | String format: YYYY-MM-DD HH:MM:SS.SSS |
timeuuid | string | string | Must be a Type 1 UUID |
tinyint | integer, string | integer | String must be a valid 8-bit integer |
uuid | string | string | Standard UUID format |
varint | integer, string | integer | Variable-length integer. Integer overflow may occur when a 32-bit or 64-bit integer is passed to a client-side decoder |