You are not logged in.
Below is the data I am trying to parse with jshon.
indicereq([{"BValue":"24940.79","Bchg":"70.10","Bpchg":"0.28","Bdt":"20160201100414"},{"NValue":"7589.70","Nchg":"26.15","Npchg":"0.35","Ndt":"20160201100415"}])
error I am getting
~ > jshon -e data < 123.txt
json read error: line 1 column 9: '[' or '{' expected near 'indicereq'
Note: this source gives faster updates as compared to the source in my previous post, so this new request!
thanks for reading
Last edited by Docbroke (2016-02-01 10:12:08)
Arch is home!
https://github.com/Docbroke
Offline
That isn't valid json...
Offline
thanks, but that is the data provided by website, (link in first post)
Is it some other type of data? can it be parsed some other way or converted to json?
Last edited by Docbroke (2016-02-01 06:09:06)
Arch is home!
https://github.com/Docbroke
Offline
I don't know what data type it is. You could parse it with awk or sed, but it would be fragile if it changes over time.
Offline
it becomes valid json if we can only keep data from "[" to "]"
invalid json
indicereq([{"BValue":"24940.79","Bchg":"70.10","Bpchg":"0.28","Bdt":"20160201100414"},{"NValue":"7589.70","Nchg":"26.15","Npchg":"0.35","Ndt":"20160201100415"}])
Valid json
[{"BValue":"24940.79","Bchg":"70.10","Bpchg":"0.28","Bdt":"20160201100414"},{"NValue":"7589.70","Nchg":"26.15","Npchg":"0.35","Ndt":"20160201100415"}]
Arch is home!
https://github.com/Docbroke
Offline
Strip it off before processing then:
sed 's/indicereq//;s/[()]//g'
Offline
worked great
w3m http://indices.moneycontrol.co.in/sensex_nifty/indtick.json?callback=jsonp1454300599978 | sed 's/indicereq//;s/[()]//g' |jshon -e 1 -e NValue -u -p -e Nchg -u > /tmp/parsed_output.txt
I was reading 'info sed' and sed - tutorial but reache only upto "sed -n '/PATTERN/p'", where I was not able to define the pattern.
thanks
BTW: is your name related with 'json'?
Arch is home!
https://github.com/Docbroke
Offline
It is pronounced the same, which given I work with web developers, is extremely annoying...
Also stop using w3m to retrieve that string: use curl.
Offline
thanks, but that is the data provided by website, (link in first post)
Is it some other type of data? can it be parsed some other way or converted to json?
It's a form of JSONP.
Offline
It is pronounced the same, which given I work with web developers, is extremely annoying...
Also stop using w3m to retrieve that string: use curl.
thanks, changed to curl from w3m.
Arch is home!
https://github.com/Docbroke
Offline
curl doesn't work on every site
~ > curl https://www1.nseindia.com//homepage/Indices1.json
<HTML><HEAD>
<TITLE>Access Denied</TITLE>
</HEAD><BODY>
<H1>Access Denied</H1>
You don't have permission to access "http://www1.nseindia.com/homepage/Indices1.json" on this server.<P>
Reference #18.5187d317.1454331129.c6a8455
</BODY>
</HTML>
same link works with w3m
However curl works with another json-data site
~ > curl http://indices.moneycontrol.co.in/sensex_nifty/indtick.json?callback=jsonp1454300599978
indicereq([{"BValue":"24824.83","Bchg":"-45.86","Bpchg":"-0.18","Bdt":"20160201153044"},{"NValue":"7555.95","Nchg":"-7.60","Npchg":"-0.10","Ndt":"20160201153048"}])
Not an issue, posting to understand the difference if someone can throw light on this.
Arch is home!
https://github.com/Docbroke
Offline
Works with curl if I add "--user-agent Mozilla/4.0".
Offline
@Docbroke,
some sites will deliberately block user agents such as curl or wget to prevent programmatic access to their resources. What they don't realize is that user agents can be easily spoofed, as Raynman demonstrated. To be on a safer side, try with an even newer user agent (not specific to this site, but in general).
Offline