Do you have to read the file first to be able to write the JSON file (C++)?

We have to be able to write JSON files for the exam (C++). However, in the exercise, the professor first read the CSV file and then wrote the JSON file.

Do you have to read it first and then write it? Or can you write a JSON file without reading it first?

I tried writing a JSON file without reading it, and I got a "null" in the JSON file. After reading it, it was written to the JSON file.

Please help.. I need it for the exam..

(2 votes)
Loading...

Similar Posts

Subscribe
Notify of
3 Answers
Oldest
Newest Most Voted
Inline Feedbacks
View all comments
NoHumanBeing
1 year ago

You want to have the data you had in the CSV in the JSON afterwards, right?

Of course, to do this it must first read the CSV and then write the JSON.

If you write before you read, the data you want to write is of course still "empty", hence the null .

In principle, it 's not necessary to read the entire CSV and then write the entire JSON. You could also read the CSV record by record and write the JSON successively. This would allow you to process a very large number of records—more than can be stored in main memory. Of course, the corresponding libraries (which read the CSV or write the JSON) would have to support this.

NackterGerd
1 year ago

If you don't have any data to write, you obviously can't write anything.

If you want to use the data from a CSV file, you must of course read it first.

If you don't need anything from the CSV file, you don't need to read the file first

beeboloko
1 year ago

Kommt aufs Dayton an