CSV to JSON Converter for Java
Free online csv to json converter with Java code examples
Working with csv to json converter in Java? Our free online csv to json converter helps Java developers format, validate, and process data instantly. Below you will find Java code examples using OpenCSV / Jackson so you can achieve the same result programmatically in your own projects.
Try the CSV to JSON Converter Online
Use our free CSV to JSON directly in your browser — no setup required.
Open CSV to JSONJava Code Example
import com.opencsv.CSVReader;
import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import java.io.StringReader;
import java.util.*;
String csv = "name,age,city\nAlice,30,New York\nBob,25,London";
CSVReader reader = new CSVReader(new StringReader(csv));
String[] headers = reader.readNext();
List<Map<String, String>> rows = new ArrayList<>();
String[] line;
while ((line = reader.readNext()) != null) {
Map<String, String> row = new LinkedHashMap<>();
for (int i = 0; i < headers.length; i++) row.put(headers[i], line[i]);
rows.add(row);
}
System.out.println(new GsonBuilder().setPrettyPrinting().create().toJson(rows));Quick Setup
Library: OpenCSV / Jackson
<!-- Maven: com.opencsv:opencsv:5.9 -->Java Tips & Best Practices
- OpenCSV handles quoted fields and escaped characters
- Use Jackson CsvMapper for direct CSV-to-JSON conversion
- Apache Commons CSV is another popular alternative