I am using an API to output a JSON file as such, and so cannot edit the format of the JSON file. Is there any way to be able to iterate through each intraday date, to find the value of open in each date?
I have tried using Object.intraday[0].open however this does not seem to work, as the it is not contained within an array?
I realise that I can use Object.intraday.date.open (where date is e.g "2018-10-19 15:59:00:"); however I want to be able to index to the different times.
{
"symbol": "AAPL",
"stock_exchange_short": "NASDAQ",
"timezone_name": "America/New_York",
"intraday": {
"2018-10-19 15:59:00:" {
"open": "219.49",
"close": "219.23",
"high": "219.61",
"low": "219.19",
"volume": "302415"
},
"2018-10-19 15:58:00:" {
"open": "219.62",
"close": "219.48",
"high": "219.70",
"low": "219.48",
"volume": "173762"
},
....
This is the pascal code that I am using in order to do this, using a test JSON of {"intraday":{"2018-10-1915:59:00":{"open":"23","low":"4"},"2018-10-1915:58:00":{"open":"25","low":"21"}}}
JSONValue := TJSONObject.ParseJSONValue('{"intraday":{"2018-10-1915:59:00":{"open":"23","low":"4"},"2018-10-1915:58:00":{"open":"25","low":"21"}}}');
j:=0;
begin
if JSONVAlue is TJSONObject then
begin
// Get the quote and low values
quote := JSONValue.GetValue<string>('intraday[0]');
low := JSONValue.GetValue<string>('intraday.low');
Memo1.Lines.Add(quote + ': ' + low);
j := j+1;
end;
end;
intradayan array.intradayis a single object with nested objects that use dates as their field names. That is a weird design choice. It would have made more sense forintradayto be an array of objects that have their dates as string fields. Whoever designed this API doesn't understand JSON and OOP very well.