How to store a json object in a column of a table?

33 views
Skip to first unread message

Debasish Sena

unread,
May 17, 2016, 7:11:37 AM5/17/16
to DataStax Java Driver for Apache Cassandra User Mailing List
Hi,

I want to store a json object in a column of a table in Cassandra. I wanted to know if at all it is possible. If possible then what will be the data type for that column? and how can I insert a json object to that column.

Thanks.

Kevin Gallardo

unread,
May 17, 2016, 7:29:00 AM5/17/16
to java-dri...@lists.datastax.com
Hi, 

I think a VARCHAR column in Cassandra should be ok. You can put the string representation of your JSON into that column. 

To deal with JSON on the driver side, you can either do a "String jsonString = row.getString("jsonCol")" and then jsonString -> your JSON library object, or use Custom codecs. Please check this : http://datastax.github.io/java-driver/manual/custom_codecs/#implementing-and-using-custom-codecs. And note that the Java driver already provides Codecs for the Jackson library and the Java library for JSON, in the driver-extras module : https://github.com/datastax/java-driver/tree/3.0/driver-extras/src/main/java/com/datastax/driver/extras/codecs/json.

--
You received this message because you are subscribed to the Google Groups "DataStax Java Driver for Apache Cassandra User Mailing List" group.
To unsubscribe from this group and stop receiving emails from it, send an email to java-driver-us...@lists.datastax.com.



--
Kévin Gallardo.
Software Engineer in Drivers and Tools Team, at DataStax.

Reply all
Reply to author
Forward
0 new messages