Read all the pages of a JSON file

Solved!
sebastienH
Level 2
Read all the pages of a JSON file

Hello,

I would like to read a JSON file. But with the URL I only access to the first page (the file is paginated). I would like to read ALL the pages.

With Talend I do a loop, but whith JSON I don't know. Can I get help ?

Thank you very much

 

0 Kudos
2 Solutions
ATsao
Dataiker

Hi Sebastien,

By default, recipes will run in "overwrite" mode in DSS. In your python recipe, try navigating to the Inputs/Outputs tab and select the Append instead of overwrite option. 

Screen Shot 2021-03-04 at 3.20.17 AM.png

This should allow the results to be appended instead of overwritten in your output dataset. I hope that this helps!

Thanks again,

Andrew

View solution in original post

0 Kudos
sebastienH
Level 2
Author

Hi,

I did not see that !! Thank you ! Problem solved

Sebastien

View solution in original post

0 Kudos
8 Replies
ATsao
Dataiker

Hi Sebastien,

Could you provide more details about this JSON file and where it's located? Are you using a download recipe or how are you trying to ingest this data into your Flow in DSS? 

Thanks,

Andrew

0 Kudos
sebastienH
Level 2
Author

Hello,

Thank you for your answer.

I get the JSON by URL https://porta....

I can only give the end of the url :

e5e3&query_id=735&offset=0    for the first page

e5e3&query_id=735&offset=1    for the second page

 

etc. There are thousands pages.

I tried a download recipe, but I canโ€™t use ยซ add another source ยป for each page. Too many pages.

 

Is it possible to do a loop ?

 

Thank you

 

0 Kudos
ATsao
Dataiker

Hi Sebastien,

Your best bet might be to create your own code recipe, such as python, where you could handle iterating through the different pages to read in the necessary data, create your own dataframe, and then write this dataframe as an output into a dataset in DSS. 

Best,

Andrew

0 Kudos
sebastienH
Level 2
Author

Hi Andrew,

Thank you for your answer. I will use a python recipe without input. I thought that an input was necessary, but it's not.

Thank you,

Best,

Sebastien

0 Kudos
ATsao
Dataiker

Hi Sebastien,

That's correct. For code recipes, only an output is necessary (even if it's a dummy output). 

Thanks,

Andrew

0 Kudos
sebastienH
Level 2
Author

Hi Andrew,

I forgot to "accept as solution", but I may have a last question.

Here is my code :

for i in range(5):
url = "https://portail.....................35&offset={0}".format(i)
fileA= pd.read_json(url, orient='records')
loop_issues1.write_from_dataframe(fileA)

The problem is that It replaces everything at each loop. But I want it to add data.

I tried to tell it "mode="a"",but it doesn't understand.

Thank you for your help. I did'nt find nothing about write_from_dataframe on pandas.pydata.org

 

0 Kudos
ATsao
Dataiker

Hi Sebastien,

By default, recipes will run in "overwrite" mode in DSS. In your python recipe, try navigating to the Inputs/Outputs tab and select the Append instead of overwrite option. 

Screen Shot 2021-03-04 at 3.20.17 AM.png

This should allow the results to be appended instead of overwritten in your output dataset. I hope that this helps!

Thanks again,

Andrew

0 Kudos
sebastienH
Level 2
Author

Hi,

I did not see that !! Thank you ! Problem solved

Sebastien

0 Kudos