Apify Discord Mirror

Updated 5 months ago

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

At a glance

The community member is trying to understand how to store an array of objects in a single JSON file, so they can connect it to table APIs or convert it to CSV. The comments suggest that datasets can only store objects, not arrays, and when running locally this will create multiple files. To solve this, the community member can either handle storing the data into a file themselves (when running locally), or run it as an actor on Apify Console which may provide various data formats to export, including CSV. The comments also mention that the Apify docs have examples for exporting data from a dataset to formats like Single JSON or CSV.

Useful resources
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.
P
N
4 comments
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.
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?
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
Add a reply
Sign up and join the conversation on Discord