how to convert CSV file to json in flutter?
NickName:maliha arash Ask DateTime:2021-06-06T21:38:06

how to convert CSV file to json in flutter?

recently i develop an ToDo application using flutter and sqflite , for backup my data i convert my database data to csv file(import data to csv file using csv package) now i want to again use this file in my application and store csv file data to my sqlite database how can i convert csv file to json? cause sqlite work with json or i should use from other approach please guide me.

static Future conertToCSVFile(List<Roznamcha> roznamcha) async {
List<List<dynamic>> data = [
  ...roznamcha.map((e) => [
        e.transactionNumber,
        e.issueDate,
        e.description,
        e.credit,
        e.debit,
        e.rate,
        e.accountNum,
      ])
];
Directory dir = Platform.isAndroid
    ? await getExternalStorageDirectory() //FOR ANDROID
    : await getApplicationSupportDirectory(); //FOR iOS

final paths = '${dir.path}/csv.csv';

String csvData = ListToCsvConverter().convert(data);

final File file = File(paths);

await file.writeAsString(csvData);

}

 static loadCsvFromStorage() async {
FilePickerResult result = await FilePicker.platform.pickFiles(
  allowedExtensions: ['csv'],
  type: FileType.custom,
);
String path = result.files.first.path;
final csvFile = new File(path).openRead();
return await csvFile
    .transform(utf8.decoder)
    .transform(
      CsvToListConverter(),
    )
    .toList();

} }

Copyright Notice:Content Author:「maliha arash」,Reproduced under the CC 4.0 BY-SA copyright license with a link to the original source and this disclaimer.
Link to original article:https://stackoverflow.com/questions/67859748/how-to-convert-csv-file-to-json-in-flutter

More about “how to convert CSV file to json in flutter?” related questions

how to convert CSV file to json in flutter?

recently i develop an ToDo application using flutter and sqflite , for backup my data i convert my database data to csv file(import data to csv file using csv package) now i want to again use this ...

Show Detail

How to convert .csv file to json?

I need to read a .csv file and convert the csv file to json format and pass the json to frontend which is the best way to read a csv file and convert to json Here my code is: fs.readFile(req.files.

Show Detail

Convert json file to csv

I have this simple python code that converts a json file into a csv. I would like to convert only the first four values of each key, but i couldn't figure out how to do it. import json import csv ...

Show Detail

How to convert blueprint json file to csv file?

How to convert blueprint json file to csv file? My target is to convert all properties parameters to a csv file from the amabri cluster Example – how to generate new fresh blueprint.json file fro...

Show Detail

Convert CSV to JSON file in python

Above csv file which contains nearly 2000 rows. I want to parse CSV file line by line and convert it to JSON and send over websocket. I found some code online which converts CSV to JSON as follo...

Show Detail

Convert csv to json returning empty json file

I am trying to convert a csv file to json using the convert-csv-to-json package from npm. I am able to get the csv from the url and the 'data.csv' is created, but the corresponding json file is jus...

Show Detail

How to convert JSON to CSV and then save to computer as CSV file

I'm currently trying to pull json data from and API, convert it to csv using the json2csv node.js module, and then save the data as a csv file on my laptop. However, when I run the script, nothing

Show Detail

How to convert a .realm file into .CSV or .json

I extracted the code from an app and I would like to convert the .realm file into .CSV or .json. I'm using Windows 11 and I'm not really teach savvy. So far: I installed MongoDB Realm studio and t...

Show Detail

how to convert this format csv file to a json file?

The CSV file looks like this way, I have the id and tags. But some tag may have multiple value, each value take one column, so some tag may have multiple columns. id,tags 403744,[&quot;&quot;] 4037...

Show Detail

I want to convert Json file to csv file using Pyhton

I have problem when i convert json file to csv i convert my csv file to json and it work but when i convert json file to csv file it don't work! HERE MY PYTHON CODE with open('orders.json') as

Show Detail