Page 1 of 1

read instruction stores only every second value

Posted: Mon Jan 28, 2019 8:49 am
by PeterF
DBK_json.txt
json input file
(851 Bytes) Downloaded 777 times
DBK.txt
strings the program should display
(931 Bytes) Downloaded 737 times
Dear Tom,

I could get stock data in a json file. To start with the most simple file, I did download only the data for one day. My idea was to write a RATS program file to read the whole file into a vector of strings. Once all strings are red, I could loop through the vector searching for those containing the pride fields for the open, high, low, close, volume and adjusted close. I just modified the example for the read instruction slightly as the strings in the file are seperated by comma, but do not include characters for carriage return and/or line feed. For test purpose, I used the following code.

Code: Select all

declare vector[string] response
open Data "C:\Users\User\Downloads\DBK.json"
read(format=cdf,varying) response
do i=1, %rows(response)
   disp response(i)
end do
disp %rows(response)
The problem is that this code only reads every second string. The number of rows is about half of the number of strings separated by comma. What do I wrong?

I have attached the json file and a text file showing the strings, which should be read by the code.

Best regards
PeterF

Re: read instruction stores only every second value

Posted: Tue Jan 29, 2019 10:05 am
by TomDoan
I'm shocked that you can even get *that* close. JSON (and similarly XML) are controlled by the punctuation, not by line breaks and are meant to be read through a parser which understands that. It's not uncommon for those files to be written as a single "line".

We have a JSON parser in the program because the OECD MEI is downloaded in JSON and we've been working on exporting reports and graphs in JSON. As we work on that, we'll see what we can do about allowing more general imports of JSON coded files.

Re: read instruction stores only every second value

Posted: Tue Jan 29, 2019 12:35 pm
by PeterF
Dear Tom,

thank you for the answer. The json-file is from yahoo finance. I inspected the file first with Chrome and noticed that the entries are separated by comma. The structure if not that complicated. If the request is for more than one day, the dates and price fields are all on chronological order. If the READ instruction would store the part following the comma at each comma, it would only be a few loops to distribute the file content into series for open, high, low, close volume and adjusted close.

If you were interested in exploring this source for parsing stock market prices from a json file into RATS series, I could provide you with more information in a private e-mail

Best regards
PeterF