JSON Support
SELECT <select-statement> and INSERT <insert-statement> statements. This support does not fundamentally alter the CQL API (for example, the schema is still enforced). It simply provides a convenient way to work with JSON documents.
SELECT JSON
SELECT statements, the JSON keyword is used to return each row as a single JSON encoded map. The remainder of the SELECT statement behavior is the same.
SELECT JSON a, ttl(b) FROM … would result in a map with keys "a" and "ttl(b)". However, there is one notable exception: for symmetry with INSERT JSON behavior, case-sensitive column names with upper-case letters will be surrounded with double quotes. For example, SELECT JSON myColumn FROM … would result in a map key "\"myColumn\"" with escaped quotes).
The map values will JSON-encoded representations (as described below) of the result set values.
INSERT JSON
INSERT statements, the new JSON keyword can be used to enable inserting a JSON encoded map as a single row. The format of the JSON map should generally match that returned by a SELECT JSON statement on the same table. In particular, case-sensitive column names should be surrounded with double quotes. For example, to insert into a table with two columns named “myKey” and “value”, you would do the following:
INSERT INTO mytable JSON '{ "\"myKey\"": 0, "value": 0}';
DEFAULT NULL is explicitly used), a column omitted from the JSON map will be set to NULL, meaning that any pre-existing value for that column will be removed (resulting in a tombstone being created). Alternatively, if the DEFAULT UNSET directive is used after the value, omitted column values will be left unset, meaning that pre-existing values for those column will be preserved.
JSON Encoding of Cassandra Data Types
JSON representation. Cassandra will also accept string representations matching the CQL literal format for all single-field types. For example, floats, ints, UUIDs, and dates can be represented by CQL literal strings. However, compound types, such as collections, tuples, and user-defined types must be represented by native JSON collections (maps and lists) or a JSON-encoded string representation of the collection.
INSERT JSON values (and from_json() arguments) as well as the format Cassandra will use when returning data for SELECT JSON statements (and from_json()):
The from_json() Function
from_json() function may be used similarly to INSERT JSON, but for a single column value. It may only be used in the VALUES clause of an INSERT statement or as one of the column values in an UPDATE, DELETE, or SELECT statement. For example, it cannot be used in the selection clause of a SELECT statement.
The to_json() Function
to_json() function may be used similarly to SELECT JSON, but for a single column value. It may only be used in the selection clause of a SELECT statement.
