Gamestudio Links
Zorro Links
Newest Posts
Data from CSV not parsed correctly
by EternallyCurious. 04/18/24 10:45
StartWeek not working as it should
by Zheka. 04/18/24 10:11
folder management functions
by VoroneTZ. 04/17/24 06:52
lookback setting performance issue
by 7th_zorro. 04/16/24 03:08
zorro 64bit command line support
by 7th_zorro. 04/15/24 09:36
Zorro FIX plugin - Experimental
by flink. 04/14/24 07:48
Zorro FIX plugin - Experimental
by flink. 04/14/24 07:46
AUM Magazine
Latest Screens
The Bible Game
A psychological thriller game
SHADOW (2014)
DEAD TASTE
Who's Online Now
1 registered members (AndrewAMD), 600 guests, and 2 spiders.
Key: Admin, Global Mod, Mod
Newest Members
EternallyCurious, 11honza11, ccorrea, sakolin, rajesh7827
19046 Registered Users
Previous Thread
Next Thread
Print Thread
Rate Thread
DataParse - support for eccentric JSON data #475919
01/13/19 21:57
01/13/19 21:57
Joined: Feb 2017
Posts: 1,725
Chicago
AndrewAMD Online OP
Serious User
AndrewAMD  Online OP
Serious User

Joined: Feb 2017
Posts: 1,725
Chicago
jcl,

I have JSON data that looks like this. I pulled it from the Darwinex API. I was hoping to have a blog entry, where I demonstrate Zorro's ability to download and parse JSON data with nothing more than a Zorro script, but maybe I will need to make and load a DLL too.

It also does not help that it starts with an eccentric element at the beginning of the array.

Code:
{
  "candles": [
    {
      "timestamp": 1532638800
    },
    {
      "candle": {
        "close": 1045.31,
        "max": 1045.31,
        "min": 1045.31,
        "open": 1045.31
      },
      "timestamp": 1532898000
    },
    {
      "candle": {
        "close": 1038.23,
        "max": 1046.22,
        "min": 1037.03,
        "open": 1045.31
      },
      "timestamp": 1532984400
    },
    {
      "candle": {
        "close": 1025.54,
        "max": 1042.31,
        "min": 1025.54,
        "open": 1038.3
      },
      "timestamp": 1533070800
    },
// etc etc


I'm thinking that in the future, it might be helpful for dataParse to support a format such as this:

Code:
const char* format = "candles,timestamp,%t,candle->max,candle->min,candle->open,candle->close";
int numparsed = dataParse(h,format,filename);
printf("nnumparsed = %d",numparsed);



Can this go on the to-do list?

Thanks,
Andrew

Re: DataParse - support for eccentric JSON data [Re: AndrewAMD] #475922
01/14/19 05:17
01/14/19 05:17
Joined: Jul 2000
Posts: 27,978
Frankfurt
jcl Offline

Chief Engineer
jcl  Offline

Chief Engineer

Joined: Jul 2000
Posts: 27,978
Frankfurt
Have you tried dataParseJSON? It's an unusual JSON format, but it could work.

Re: DataParse - support for eccentric JSON data [Re: jcl] #475933
01/14/19 14:05
01/14/19 14:05
Joined: Feb 2017
Posts: 1,725
Chicago
AndrewAMD Online OP
Serious User
AndrewAMD  Online OP
Serious User

Joined: Feb 2017
Posts: 1,725
Chicago
Oh, I meant to use DataParseJSON.

But... it still didn't work using this code:
Code:
int h = 1;
const char* format = "candles,timestamp,%t,max,min,open,close";
int numparsed = dataParseJSON(h,format,filename);
printf("\nnumparsed = %d",numparsed);



I attached the JSON file for your reference.

Thanks,
Andrew

Attached Files
scs_1d.zip (56 downloads)
Re: DataParse - support for eccentric JSON data [Re: AndrewAMD] #476307
02/16/19 09:36
02/16/19 09:36
Joined: Jul 2000
Posts: 27,978
Frankfurt
jcl Offline

Chief Engineer
jcl  Offline

Chief Engineer

Joined: Jul 2000
Posts: 27,978
Frankfurt
As far as I see the data is only mildly eccentric. Candle and timestamp are stored in 2 objects, so Zorro would parse any candle twice. Remove the two extra brackets with a search-replace operation, then you can parse it. Or parse it unchanged and then remove the redundant lines with dataCompress.

void main()
{
dataParseJSON(1,"candles,timestamp,%t,max,min,open,close,,","scs_1d.json");
dataSave(1,"jsontest.t6");
}


Moderated by  Petra 

Gamestudio download | chip programmers | Zorro platform | shop | Data Protection Policy

oP group Germany GmbH | Birkenstr. 25-27 | 63549 Ronneburg / Germany | info (at) opgroup.de

Powered by UBB.threads™ PHP Forum Software 7.7.1