How to store array of objects in the same json file?

I don't really understand datasets. I want to store an array of objects in the same json file. So i can connect this json file to table api's or convert them to csv.
3 Replies
Pepa J
Pepa J3y ago
Dataset is capable to store objects only, so when you try to push and array into the dataset it will be stored as several object - when running locally this will create several files. To solve this you may handle storing into file by yourself (when running locally), or you may run it as an actor on Apify Console (https://console.apify.com/) which may provide you various dataformats to export including CSV.
Apify
Apify Console
Manage the Apify platform and your account.
unwilling-turquoise
unwilling-turquoiseOP3y ago
What do you mean by storing into file by yourself? Does datasets support storing everything into one file? or do i need to use a seperate db for it?
Pepa J
Pepa J3y ago
If you take a look at Apify docs you may find plenty of examples for exporting data from dataset to other formats like Single JSON or CSV. https://docs.apify.com/academy/web-scraping-for-beginners/data-collection/save-to-csv https://docs.apify.com/sdk/js/reference/next/class/Dataset#exportToCSV
Saving results to CSV | Apify Documentation
Learn how to save the results of your scraper's collected data to a CSV file that can be opened in Excel, Google Sheets, or any other spreadsheets program.
Dataset | API | Apify Documentation
The Dataset class represents a store for structured data where each object stored has the same attributes, such as online store products or real estate offers. You can imagine it as a table, where each object is a row and its attributes are columns. Dataset is an append-only storage - you can only add new records to it but you cannot modify or...

Did you find this page helpful?