Formatting query results as JSON

Use CQL SELECT keywords to retrieve data from a table in the JSON format. For more information, see What’s New in Cassandra 2.2: JSON Support.

Retrieving all results in the JSON format

To get this result, insert the JSON keyword between the SELECT command and the data specifications. For example:

cqlsh:cycling> select json name, checkin_id, timestamp from checkin;
 {"name": "BRAND", "checkin_id": "50554d6e-29bb-11e5-b345-feff8194dc9f", "timestamp": "2016-08-28 21:45:10.406Z"}
  {"name": "VOSS", "checkin_id": "50554d6e-29bb-11e5-b345-feff819cdc9f", "timestamp": "2016-08-28 21:44:04.113Z"}
(2 rows)

Retrieving selected columns in JSON format

To specify the JSON format for a selected column, enclose its name in toJson(). For example:

cqlsh:cycling> select name, checkin_id, toJson(timestamp) from checkin;

 name  | checkin_id                           | system.tojson(timestamp)
 BRAND | 50554d6e-29bb-11e5-b345-feff8194dc9f | "2016-08-28 21:45:10.406Z"
  VOSS | 50554d6e-29bb-11e5-b345-feff819cdc9f | "2016-08-28 21:44:04.113Z"

DataStax Enterprise supports returning a JSON-formatted timestamp with complete time zone information.

Was this helpful?

Give Feedback

How can we improve the documentation?

© 2024 DataStax | Privacy policy | Terms of use

Apache, Apache Cassandra, Cassandra, Apache Tomcat, Tomcat, Apache Lucene, Apache Solr, Apache Hadoop, Hadoop, Apache Pulsar, Pulsar, Apache Spark, Spark, Apache TinkerPop, TinkerPop, Apache Kafka and Kafka are either registered trademarks or trademarks of the Apache Software Foundation or its subsidiaries in Canada, the United States and/or other countries. Kubernetes is the registered trademark of the Linux Foundation.

General Inquiries: +1 (650) 389-6000,