Gamestudio Links
Zorro Links
Newest Posts
Trading Journey
by howardR. 04/28/24 09:55
basik85278
by basik85278. 04/28/24 08:56
Zorro Trader GPT
by TipmyPip. 04/27/24 13:50
Help with plotting multiple ZigZag
by M_D. 04/26/24 20:03
Data from CSV not parsed correctly
by jcl. 04/26/24 11:18
M1 Oversampling
by jcl. 04/26/24 11:12
Why Zorro supports up to 72 cores?
by jcl. 04/26/24 11:09
Eigenwerbung
by jcl. 04/26/24 11:08
AUM Magazine
Latest Screens
The Bible Game
A psychological thriller game
SHADOW (2014)
DEAD TASTE
Who's Online Now
3 registered members (alibaba, howardR, basik85278), 756 guests, and 3 spiders.
Key: Admin, Global Mod, Mod
Newest Members
wandaluciaia, Mega_Rod, EternallyCurious, howardR, 11honza11
19049 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,986
Frankfurt
jcl Offline

Chief Engineer
jcl  Offline

Chief Engineer

Joined: Jul 2000
Posts: 27,986
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 (57 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,986
Frankfurt
jcl Offline

Chief Engineer
jcl  Offline

Chief Engineer

Joined: Jul 2000
Posts: 27,986
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