How to display JSON.parse reviver?
Hi,
Am teaching myself and can receive data in the console with the following script. I am want to publish the JSON data to an HTML document.
code is:
var ws = new WebSocket('wss://ws.binaryws.com/websockets/v3?app_id=XXX'); ws.onopen = function(evt) { ws.send(JSON.stringify({ "ticks_history": "frxGBPUSD","end": "latest","count": 86400,"style":"candles","granularity": 3600 })); } ws.onmessage = function(msg) { var data = JSON.parse(msg.data); console.log('ticks_history update: %o', data) }
JSON.parse() requires a reviver for this Can someone point me in the right direction please?
Many thanks...
Best Answer
-
@Middleend code depends on what html you choose to display data. For reference you can check this http://stackoverflow.com/questions/20467785/how-to-convert-json-object-to-html-data
When you make this call you get data like this
{ "candles": [ { "close": "1.2138", "epoch": 1484012780, "high": "1.2144", "low": "1.2136", "open": "1.2143" }, { "close": "1.2165", "epoch": 1484013600, "high": "1.2176", "low": "1.2136", "open": "1.2138" } ], "echo_req": { "count": 86400, "end": "latest", "granularity": 3600, "style": "candles", "ticks_history": "frxGBPUSD" }, "msg_type": "candles" }
so this
var data = JSON.parse(msg.data);
gives you javascript object then you can use it like this to get datadata.candles[0].high # to get first candle high
ordata.msg_type or data["msg_type"]
Answers
Thank you, thank you, thank you.....perfect pointer....much appreciated.