javascript - how to load json file from local system and assign to some variable -
i want store json file local system cassandra column, newer version of cassandra supports json data. solution, looking approach this:-
globalvariable<-load json file local system. cassandracolumn<-dump(globalvariable) third thing want know type of cassandracolumn, support, entire json data, whether text or blob.
i don't know whether possible or not.your's suggestions highly appreciated. using cassandra2.2.4 on ubuntu 14.04 lts system.
i tried far: 1.var data = params.jsondata; //assign entire json data variable 2. var insertquery = "insert " +keyspace+ "."+table_name+ " json '{"+data+"}';"; console.log(insertquery); client.execute(insertquery, function(err, result2){ if(result2){ return res.json("data inserted"); } else{ return res.json("data insertion failed"); } });
i did wrong while preparing insertquery.
on console log : insert jsondb.iris json '{[object object]}'; response : “data insertion failed” application: rest api creation
i not passing json data directly cassandra, in case have pass jsondata through rest api body part. have collect entire json data , dump cassandra columns
there 2 possible answers question
1) if json files have clear structure, can design cassandra table matches structure, using user defined types if necessary encode nested structure. can insert json content cassandra using insert statements like.
create table example ( id int primary key, tupleval tuple<int, text>, numbers set<int>, words list<text> ) insert example json '{"id": 0, "tupleval": [1, "abc"], "numbers": [1, 2, 3], "letters": ["a", "b", "c"]}';
2) if json files not have schema, in case store them blob of text
create tabme my_json( id int, json text, primary key(id) ); insert my_json(id,json) values(1, '{"1": "foo", "2": "bar"}');
a warning though, avoid store huge blob of json data (like payload worth of 10mb), you'll face read performance issues.
Comments
Post a Comment