Posted In: Jackson 2X, JSON

Converting CSV to JSON using Jackson library

Maven Jackson 2X Classes used

Read More

Tags: Tags:

by , on August 31st, 2017

Posted In: JSON, XML

How to convert XML to JSON using org.json.XML

Result

Read More

Tags: Tags:

by , on August 31st, 2017

Posted In: Java Core, JSON

Converting JSON to CSV in Java using Arkni – json-to-csv

Download org.jsontocsv.parser.JSONFlattener from Arkni – json-to-csv package com.example.csv; import java.util.List; import java.util.Map; import org.jsontocsv.parser.JSONFlattener; import org.jsontocsv.writer.CSVWriter; import org.junit.Test; public class JsonToCsv2 { @Test public void jsontocsv() throws Exception { System.out.println(“jsontocsv started”); try { List flatJson = JSONFlattener .parseJson(jsonString()); CSVWriter.writeToFile(CSVWriter.getCSV(flatJson, “,”), “E:/files/outcsv1.csv”); } catch (Exception e) { e.printStackTrace(); } } private static String jsonString() { return […]

Read More

Tags: Tags:

by , on August 31st, 2017

Posted In: Java Core, JSON

Converting JSON to CSV in Java using org.json.CDL

Example first reads file and the creates JSONArray. After that it again creates CSV string and writes to a CSV file. package com.example.csv; import java.io.BufferedReader; import java.io.File; import java.io.FileNotFoundException; import java.io.FileReader; import org.apache.commons.io.FileUtils; import org.json.CDL; import org.json.JSONArray; import org.junit.Test; public class JsonToCsv { private StringBuilder sb = new StringBuilder(); @Test public void jsontocsv() throws Exception […]

Read More

Tags: Tags:

by , on August 31st, 2017

Posted In: Java Core

How to read and parse CSV file using Scanner

Example will not work with elements with comma inside quotes package com.example.csv; import java.io.File; import java.io.FileNotFoundException; import java.util.Scanner; import org.junit.Test; public class CvsScanner { @Test public void parser1() throws Exception { System.out.println(“\nparser1 started”); String filepath= “E:/files/cm24AUG2017bhav.csv”; Scanner scanner = null; try { File file = new File(filepath); scanner = new Scanner(file); scanner.useDelimiter(“,”); while (scanner.hasNext()) { […]

Read More

Tags: Tags:

by , on August 31st, 2017

Posted In: Java Core, String

How to read and parse CSV file using Guava Splitter

Splitting a comma-separated string but ignoring commas in quotes Maven guava Guava Splitter Works only without commas in quotes data Works with commas in quotes data

Read More

Tags: Tags:

by , on August 29th, 2017

Posted In: Java Core, String

How to read and parse CSV file using String Pattern

Splitting a comma-separated string but ignoring commas in quotes Parsing CSV input with a RegEx in java

Read More

Tags: Tags:

by , on August 29th, 2017

Posted In: Java Core, String

How to read and parse CSV file using Open CSV

Splitting a comma-separated string but ignoring commas in quotes Maven opencsv Example csv (cm24AUG2017bhav.csv) Example csv commas in quotes (cm24AUG2017bhav1.csv) opencsv import With deprecated CSVReader. Use CSVReaderBuilder With deprecated CSVReader. Use CSVReaderBuilder. commas in quotes data With CSVReaderBuilder With CSVReaderBuilder. commas in quotes data With CsvToBean and ColumnPositionMappingStrategy. CsvToBean.parse is deprecated With header element name

Read More

Tags: Tags:

by , on August 29th, 2017

Posted In: Java Core, String

How to read and parse CSV file using Apache Commons CSV

Splitting a comma-separated string but ignoring commas in quotes Maven commons-csv Example csv Example csv commons csv import With element index With header element name With header name and with commas in quotes With header name RFC4180 format

Read More

Tags: Tags:

by , on August 29th, 2017