Problems with parsing strings in objects in javascript and JSON

I query the Cassandra database and then try to convert one of its BLOB records to a javascript object.

There is currently one line that receives the / blob data that interests me:

data[x][0]

When I console.log it using:

console.log("data[x][0]: ", data[x][0]);

Conclusion:

data[x][0]:  <Buffer 7b 22 70 72 65 66 69 78 22 3a 20 22 65 6e 77 69 6b 69 22 2c 20 22 74 69 74 6c 65 22 3a 20 22 22 41 67 68 6e 61 64 61 72 72 61 67 68 22 22 7d>

So, I completed my hexadecimal buffer object (which I saw earlier), so I tried to turn it into a string using the toString () method, after which, perhaps, we can parse it and turn it into a javascript object!

So, first I tested the toString () method:

console.log("data[x][0].toString(): ", data[x][0].toString());

Below is the conclusion:

data[x][0].toString():  {"prefix": "enwiki", "title": ""Aghnadarragh""}

Which one looks great! This is the object I'm trying to create! (Although now this is a string)

So ... why not make out the flesh with JSON? This is like JSON ...

console.log( "JSON.string(data[x][0]): ", JSON.parse( data[x][0].toString() ) );

, , , JSON:

events.js:72
        throw er; // Unhandled 'error' event
              ^
SyntaxError: Unexpected token A
    at Object.parse (native)
    at CassandraBackend.queryCB2 (/home/brandomiranda/Documents/6.S194/testreduce/CassandraBackend.js:831:70)
    at Object.callback (/home/brandomiranda/Documents/6.S194/testreduce/node_modules/node-cassandra-cql/index.js:248:16)
    at Connection.handleFrame (/home/brandomiranda/Documents/6.S194/testreduce/node_modules/node-cassandra-cql/lib/connection.js:244:15)
    at FrameParser.<anonymous> (/home/brandomiranda/Documents/6.S194/testreduce/node_modules/node-cassandra-cql/lib/connection.js:45:12)
    at FrameParser.EventEmitter.emit (events.js:92:17)
    at emitReadable_ (_stream_readable.js:408:10)
    at emitReadable (_stream_readable.js:404:5)
    at readableAddChunk (_stream_readable.js:165:9)
    at FrameParser.Readable.push (_stream_readable.js:127:10)

, , , , (, , JSON, ).

, JSON, ? , , , :

Doing:

console.log(typeof data[x][0]);

:

object

Javascript-?


: Cassandra 2.0.5

, , , :

https://github.com/gwicke/testreduce/blob/master/CassandraBackend.js#L830

, data[x][0] Cassandra blob.

data[x] Cassandra. data[x][0] . , , db, :

query: 'select test, score from test_by_score where commit = ?'

, 0 "test" table test_by_score. blob :

    CREATE TABLE IF NOT EXISTS test_by_score (
        commit blob, 
        delta int, 
        score int, 
        test blob, 
    PRIMARY KEY(commit, delta, test) );

, , - , JSON ... , , JSON... ? !


gitissue

gitissue github, , , ( , .

https://github.com/gwicke/testreduce/issues/43

Gitissue , , .

+4
1

, : , , Cassandra . JSON .

: upserts ( , ), : "Aadit M Shah" , , , , . , RegExp, .

JSON.parse(data[x][0].toString().replace(/\"\"\(.*)\"\"/g, /\"\'$1\'\"/)

.

BLOB VARCHAR, : java- cassandra JSON. ?

+1

Source: https://habr.com/ru/post/1539087/


All Articles