Hi @Tomasz,
I was trying to parse the json string which I had got it from Rest call but I dont know how to access specific attribute.
Below is the Json string which I got it from rest call and if I want to get the "sell_price" if the tradingsymbol="BANKNIFTY23N0842800CE"
{
"status": "success",
"data": {
"net": [
{
"tradingsymbol": "BANKNIFTY23N0842800CE",
"exchange": "NFO",
"instrument_token": 10420482,
"product": "NRML",
"quantity": 375,
"overnight_quantity": -375,
"multiplier": 1,
"average_price": 310,
"close_price": 306.3,
"last_price": 490,
"value": 116250,
"pnl": 67500,
"m2m": 68887.5,
"unrealised": 67500,
"realised": 0,
"buy_quantity": 0,
"buy_price": 0,
"buy_value": 0,
"buy_m2m": 0,
"sell_quantity": 375,
"sell_price": 310,
"sell_value": 116250,
"sell_m2m": 114862.5,
"day_buy_quantity": 0,
"day_buy_price": 0,
"day_buy_value": 0,
"day_sell_quantity": 0,
"day_sell_price": 0,
"day_sell_value": 0
},
{
"tradingsymbol": "BANKNIFTY23N0842800PE",
"exchange": "NFO",
"instrument_token": 10420738,
"product": "NRML",
"quantity": 375,
"overnight_quantity": 375,
"multiplier": 1,
"average_price": 322.344,
"close_price": 331.15,
"last_price": 132.3,
"value": -120879,
"pnl": -71266.5,
"m2m": -74568.74999999997,
"unrealised": 71266.5,
"realised": 0,
"buy_quantity": 375,
"buy_price": 322.344,
"buy_value": 120879,
"buy_m2m": 124181.24999999999,
"sell_quantity": 0,
"sell_price": 0,
"sell_value": 0,
"sell_m2m": 0,
"day_buy_quantity": 0,
"day_buy_price": 0,
"day_buy_value": 0,
"day_sell_quantity": 0,
"day_sell_price": 0,
"day_sell_value": 0
},
{
"tradingsymbol": "NIFTY23N0219050CE",
"exchange": "NFO",
"instrument_token": 12820994,
"product": "NRML",
"quantity": 0,
"overnight_quantity": 0,
"multiplier": 1,
"average_price": 0,
"close_price": 0,
"last_price": 83.25,
"value": 1335,
"pnl": 1335,
"m2m": 1335,
"unrealised": 1335,
"realised": 0,
"buy_quantity": 50,
"buy_price": 83.2,
"buy_value": 4160,
"buy_m2m": 4160,
"sell_quantity": 50,
"sell_price": 109.9,
"sell_value": 5495,
"sell_m2m": 5495,
"day_buy_quantity": 50,
"day_buy_price": 83.2,
"day_buy_value": 4160,
"day_sell_quantity": 50,
"day_sell_price": 109.9,
"day_sell_value": 5495
},
{
"tradingsymbol": "NIFTY23N0219250PE",
"exchange": "NFO",
"instrument_token": 12823298,
"product": "NRML",
"quantity": 0,
"overnight_quantity": 0,
"multiplier": 1,
"average_price": 0,
"close_price": 0,
"last_price": 116.8,
"value": -507.5,
"pnl": -507.5,
"m2m": -507.5,
"unrealised": -507.5,
"realised": 0,
"buy_quantity": 50,
"buy_price": 111.2,
"buy_value": 5560,
"buy_m2m": 5560,
"sell_quantity": 50,
"sell_price": 101.05,
"sell_value": 5052.5,
"sell_m2m": 5052.5,
"day_buy_quantity": 50,
"day_buy_price": 111.2,
"day_buy_value": 5560,
"day_sell_quantity": 50,
"day_sell_price": 101.05,
"day_sell_value": 5052.5
}
],
"day": [
{
"tradingsymbol": "NIFTY23N0219050CE",
"exchange": "NFO",
"instrument_token": 12820994,
"product": "NRML",
"quantity": 0,
"overnight_quantity": 0,
"multiplier": 1,
"average_price": 0,
"close_price": 0,
"last_price": 83.25,
"value": 1335,
"pnl": 1335,
"m2m": 1335,
"unrealised": 1335,
"realised": 0,
"buy_quantity": 50,
"buy_price": 83.2,
"buy_value": 4160,
"buy_m2m": 4160,
"sell_quantity": 50,
"sell_price": 109.9,
"sell_value": 5495,
"sell_m2m": 5495,
"day_buy_quantity": 50,
"day_buy_price": 83.2,
"day_buy_value": 4160,
"day_sell_quantity": 50,
"day_sell_price": 109.9,
"day_sell_value": 5495
},
{
"tradingsymbol": "NIFTY23N0219250PE",
"exchange": "NFO",
"instrument_token": 12823298,
"product": "NRML",
"quantity": 0,
"overnight_quantity": 0,
"multiplier": 1,
"average_price": 0,
"close_price": 0,
"last_price": 116.8,
"value": -507.5,
"pnl": -507.5,
"m2m": -507.5,
"unrealised": -507.5,
"realised": 0,
"buy_quantity": 50,
"buy_price": 111.2,
"buy_value": 5560,
"buy_m2m": 5560,
"sell_quantity": 50,
"sell_price": 101.05,
"sell_value": 5052.5,
"sell_m2m": 5052.5,
"day_buy_quantity": 50,
"day_buy_price": 111.2,
"day_buy_value": 5560,
"day_sell_quantity": 50,
"day_sell_price": 101.05,
"day_sell_value": 5052.5
}
]
}
}
Below is one way I tried to get the tradingsymbol but no luck.
EnableScript("jscript");
<%
function _ParsePosition( json_string)
{
var result;
try {
result = JSON.parse( json_string );
result = item in result.data.net[0].tradingsymbol;
} catch (e) {
result=JSON.parse( "{\"status\": \"error\"}" );
}
return result
}
%>
function ParsePositionJSON( json_string ) {
json = "";
if(json_string != ""){
script = GetScriptObject();
json = script._Parse( json_string );
}
return json;
}
Below is the code in AFL to get the "status" which is working but when I try to get "data" and next levels, I could not.
EnableScript("jscript");
<%
function _ParsePosition( json_string)
{
var result;
try {
result = JSON.parse( json_string );
} catch (e) {
result=JSON.parse( "{\"status\": \"error\"}" );
}
return result
}
%>
function ParsePositionJSON( json_string ) {
json = "";
if(json_string != ""){
script = GetScriptObject();
json = script._Parse( json_string );
}
return json;
}
jsonObj = ParsePositionJSON(jsonStr);
_TRACE("tradingsymbol = " + jsonObj.status);//this is working
_TRACE("tradingsymbol = " + jsonObj.status.data.net[0].tradingsymbol);//not working
Just for Reference: If I do the same in JavaScript, below is the output (in Chrome console).
can I do it in AFL?