Yeah thats going to be annoying to handle. You might be best to take a look at the old JSON parser published by KX here: https://github.com/KxSystems/kdb/blob/master/e/json.k<o:p></o:p>
<o:p> </o:p>
(I believe this was published before .j.k was added to KDB)<o:p></o:p>
<o:p> </o:p>
It might be best to modify this parser to handle the bad JSON you are receiving. Alternatively as a rough workaround you could do some pre-processing on the strings to try and convert them into valid JSON<o:p></o:p>
<o:p> </o:p>
For example (using ws.q I posted previously)<o:p></o:p>
<o:p> </o:p>
$ q ws.q<o:p></o:p>
KDB+ 3.5 2017.11.30 Copyright (C) 1993-2017 Kx Systems<o:p></o:p>
l64/ 8()core 16048MB jmcmurray homer.aquaq.co.uk 127.0.1.1 EXPIRE 2018.06.30 AquaQ #50170<o:p></o:p>
<o:p> </o:p>
q).spx.k:{.j.k “"“sv(0,asc raze 1 1 0+'x ss/:”{,:”)cut x}<o:p></o:p>
q).spx.upd:{show .spx.k x}<o:p></o:p>
q).spx.h:.ws.open[“wss://otcsf.spreadex.com”;`.spx.upd]<o:p></o:p>
q).spx.h .j.j cmd
token!authenticate
guest<o:p></o:p>
q)type | “authenticate”<o:p></o:p>
successful| “true”<o:p></o:p>
keepAlive | “6000”<o:p></o:p>
nodeId | ,“6”<o:p></o:p>
serverTime| “1521813347131”<o:p></o:p>
type| “poll”<o:p></o:p>
.spx.h .j.j cmd
drefdepth!(
subscribe;“TraFinSprXGrp|105”;2)<o:p></o:p>
q)'illegal char * at 101<o:p></o:p>
'illegal char D at 82<o:p></o:p>
'illegal char D at 87<o:p></o:p>
'illegal char D at 86<o:p></o:p>
'illegal char G at 80<o:p></o:p>
'illegal char E at 80<o:p></o:p>
'illegal char D at 90<o:p></o:p>
dref | “TraFinSprXMkt|87791”<o:p></o:p>
sell | 11961f<o:p></o:p>
hash | “A8-43-EB-66-E1”<o:p></o:p>
buy | 11962f<o:p></o:p>
timestamp| “5248260119971866533”<o:p></o:p>
chg | -122.5<o:p></o:p>
dref | “TraFinSprXMkt|83430”<o:p></o:p>
sell | 1.23343<o:p></o:p>
hash | “27-4D-0D-7E-B8”<o:p></o:p>
buy | 1.23349<o:p></o:p>
timestamp| “5248260119972511089”<o:p></o:p>
chg | 0.00154<o:p></o:p>
<o:p> </o:p>
Here the .spx.k function attempts to reconstruct the JSON with the quotation marks inserted. This is done in a fairly naïve way, and clearly doesnt work for all messages (hence the illegal char errors I think the problem in most of these is the presence of commas within strings inside the JSON-like object), but it may be at least a starting point for you to build upon.<o:p></o:p>
<o:p> </o:p>
Hope this helps<o:p></o:p>
Jonathon<o:p></o:p>
<o:p> </o:p>
From:‘Student’ via Kdb+ Personal Developers <personal-kdbplus@googlegroups.com>
Sent: 22 March 2018 20:28
To: Kdb+ Personal Developers <personal-kdbplus@googlegroups.com>
Subject: [personal kdb+] Re: KDB+ Websocket Invalid Handle<o:p></o:p>
<o:p> </o:p>
Very useful. Thanks again. <o:p></o:p>
<o:p> </o:p>
I’m having trouble with the second websocket. The JSON that’s coming out of it doesn’t have quotes around the variable names, so it’s not really ‘valid’ JSON. I’m having difficulty parsing the incoming messages and saving them to a table. The code to subscribe to that websocket is as follows:<o:p></o:p>
<o:p> </o:p>
.z.ws:{0N!x;}; / print incoming msgs to console, no echo.<o:p></o:p>
r:(`$“:wss://otcsf.spreadex.com”)“GET / HTTP/1.1\r\nHost: otcsf.spreadex.com\r\nUpgrade: websocket\r\nConnection: Upgrade\r\nOrigin: otcsf.spreadex.com\r\nSec-WebSocket-Version: 13\r\n\r\n”;<o:p></o:p>
neg[r 0]“{"cmd":"authenticate","token":"guest"}”<o:p></o:p>
neg[r 0]“{"cmd":"subscribe","dref":"TraFinSprXGrp|105","depth":2}”<o:p></o:p>
<o:p> </o:p>
Should I try to parse this just with delimiters, or is there an easier way to do this?<o:p></o:p>
<o:p> </o:p>
<o:p> </o:p>
<o:p> </o:p>
On Wednesday, March 21, 2018 at 7:00:17 PM UTC, Student wrote:<o:p></o:p>
Hi,<o:p></o:p>
<o:p> </o:p>
I can connect to the following websocket without a problem. (I have SSL_VERIFY_CLIENT set to NO as an Environment Variable.)<o:p></o:p>
<o:p> </o:p>
//wss://api.bitfinex.com/ws/2
//{“event”:“subscribe”,“pair”:“BTCUSD”,“channel”:“ticker”}
.z.ws:{0N!x;};
r:(`$“:wss://api.bitfinex.com”)“GET /ws/2 HTTP/1.1\r\nHost: api.bitfinex.com\r\n\r\n”;r
neg[r 0]“{"event":"subscribe","pair":"BTCUSD","channel":"ticker"}”<o:p></o:p>
<o:p> </o:p>
Why can’t I connect to the following websocket? The handle just comes back as invalid. <o:p></o:p>
<o:p> </o:p>
//wss://otcsf.spreadex.com/
.z.ws:{0N!x;};
r:(`$“:wss://otcsf.spreadex.com”)“GET / HTTP/1.1\r\nHost: otcsf.spreadex.com\r\n\r\n”;r<o:p></o:p>
<o:p> </o:p>
Both websockets work if I just test them at https://www.websocket.org/echo.html. <o:p></o:p>
<o:p> </o:p>
<o:p> </o:p>
<o:p> </o:p>
<o:p> </o:p>
–
Submitted via Google Groups