{"id":112388,"date":"2022-05-27T11:00:00","date_gmt":"2022-05-27T08:00:00","guid":{"rendered":"https:\/\/examples.javacodegeeks.com\/?p=112388"},"modified":"2022-05-24T16:35:20","modified_gmt":"2022-05-24T13:35:20","slug":"convert-csv-to-json-using-java","status":"publish","type":"post","link":"https:\/\/examples.javacodegeeks.com\/convert-csv-to-json-using-java\/","title":{"rendered":"Convert CSV to Json using Java"},"content":{"rendered":"<h2 class=\"wp-block-heading\" id=\"h-1-introduction\">1. Introduction<\/h2>\n<p>A comma-separated values (CSV) file is a delimited text file that uses a comma to separate values. Each line of the file is a data record. Each record consists of one or more fields, separated by commas. The use of the comma as a field separator is the source of the name for this file format. A CSV file typically stores tabular data (numbers and text) in plain text, in which case each line will have the same number of fields. The CSV file format is not fully standardized. Separating fields with commas is the foundation, but commas in the data or embedded line breaks have to be handled specially. Some implementations disallow such content while others surround the field with quotation marks, which yet again creates the need for escaping if quotation marks are present in the data.<\/p>\n<p>JSON (JavaScript Object Notation) is a lightweight data-interchange format. It is easy for humans to read and write. It is easy for machines to parse and generate. It is based on a subset of the JavaScript Programming Language Standard ECMA-262 3rd Edition &#8211; December 1999. JSON is a text format that is completely language-independent but uses conventions that are familiar to programmers of the C-family of languages, including C, C++, C#, Java, JavaScript, Perl, Python, and many others. These properties make JSON an ideal data-interchange language.<\/p>\n<h2 class=\"wp-block-heading\" id=\"h-2-setup\">2. Setup<\/h2>\n<p>In this section, we will see how to set up our java project. We will use the <code>org.json.json<\/code> library for our purpose. The files in this package implement JSON encoders\/decoders in Java. It also includes the capability to convert between JSON and XML, HTTP headers, Cookies, and CDL. Create a maven project and include the below dependency in your project:<\/p>\n<div class=\"wp-block-syntaxhighlighter-code \">\n<pre class=\"brush: xml; title: ; notranslate\" title=\"\">\n&lt;dependencies&gt;\n    &lt;dependency&gt;\n        &lt;groupId&gt;org.json&lt;\/groupId&gt;\n        &lt;artifactId&gt;json&lt;\/artifactId&gt;\n        &lt;version&gt;20220320&lt;\/version&gt;\n    &lt;\/dependency&gt;\n&lt;\/dependencies&gt;\n<\/pre>\n<\/div>\n<p>Your pom file will look something like the below:<\/p>\n<p><span style=\"text-decoration: underline\"><em>pom.xml<\/em><\/span><\/p>\n<div class=\"wp-block-syntaxhighlighter-code \">\n<pre class=\"brush: xml; title: ; notranslate\" title=\"\">\n&lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot;?&gt;\n&lt;project xmlns=&quot;http:\/\/maven.apache.org\/POM\/4.0.0&quot;\n         xmlns:xsi=&quot;http:\/\/www.w3.org\/2001\/XMLSchema-instance&quot;\n         xsi:schemaLocation=&quot;http:\/\/maven.apache.org\/POM\/4.0.0 http:\/\/maven.apache.org\/xsd\/maven-4.0.0.xsd&quot;&gt;\n    &lt;modelVersion&gt;4.0.0&lt;\/modelVersion&gt;\n\n    &lt;groupId&gt;org.example&lt;\/groupId&gt;\n    &lt;artifactId&gt;JavaCodeGeeks&lt;\/artifactId&gt;\n    &lt;version&gt;1.0-SNAPSHOT&lt;\/version&gt;\n\n    &lt;properties&gt;\n        &lt;maven.compiler.source&gt;16&lt;\/maven.compiler.source&gt;\n        &lt;maven.compiler.target&gt;16&lt;\/maven.compiler.target&gt;\n    &lt;\/properties&gt;\n\n    &lt;dependencies&gt;\n        &lt;dependency&gt;\n            &lt;groupId&gt;org.json&lt;\/groupId&gt;\n            &lt;artifactId&gt;json&lt;\/artifactId&gt;\n            &lt;version&gt;20220320&lt;\/version&gt;\n        &lt;\/dependency&gt;\n    &lt;\/dependencies&gt;\n\n&lt;\/project&gt;\n<\/pre>\n<\/div>\n<h2 class=\"wp-block-heading\" id=\"h-3-csv-to-json\">3. CSV to JSON<\/h2>\n<p>In this section, we will see how to convert a CSV file to JSON. First, we will create a test CSV file in the resource folder. The resource folder is already in the classpath so it&#8217;s easy to access the files inside it. Below is the sample CSV file which we will convert to JSON:<\/p>\n<p><span style=\"text-decoration: underline\"><em>input.csv<\/em><\/span><\/p>\n<div class=\"wp-block-syntaxhighlighter-code \">\n<pre class=\"brush: plain; title: ; notranslate\" title=\"\">\nFirst name, Surname, Gender, Date of Birth\nTom, Cruise, Male, 01-01-1966\nShahrukh, Khan, Male, 02-02-1955\n<\/pre>\n<\/div>\n<p>As you can see that this file is very simple and only contains two records. The first line is the header and second onwards we got data. Now let us start writing the Java code to read this file and then convert it to JSON.<div style=\"display:inline-block; margin: 15px 0;\"> <div id=\"adngin-JavaCodeGeeks_incontent_video-0\" style=\"display:inline-block;\"><\/div> <\/div><\/p>\n<p>First, let us read this file into a stream:<\/p>\n<div class=\"wp-block-syntaxhighlighter-code \">\n<pre class=\"brush: plain; title: ; notranslate\" title=\"\">\nInputStream inputStream = CsvToJson.class.getClassLoader().getResourceAsStream(&quot;input.csv&quot;);\n<\/pre>\n<\/div>\n<p>The getResourceAsStream() method returns an input stream for reading the specified resource(in our case the csv file). <\/p>\n<p>Now let us read this stream and convert it into a string which we need to construct our JSON file. First, let&#8217;s create a BufferedReader from the given input stream:<\/p>\n<div class=\"wp-block-syntaxhighlighter-code \">\n<pre class=\"brush: java; title: ; notranslate\" title=\"\">\nnew BufferedReader(new InputStreamReader(inputStream))\n<\/pre>\n<\/div>\n<p>The BufferedReader class is used to read text from a character-input stream, buffering characters so as to provide for the efficient reading of characters, arrays, and lines. The buffer size may be specified, or the default size may be used. The default is large enough for most purposes. In general, each read request made by a Reader causes a corresponding read request to be made of the underlying character or byte stream. It is therefore advisable to wrap a BufferedReader around any Reader whose read() operations may be costly. <\/p>\n<p>Now let us call the <code>lines()<\/code> method on the above stream. It returns a <code>Stream<\/code>, the elements of which are lines read from this <code>BufferedReader<\/code>. The <code>Stream<\/code> is lazily populated, i.e., read-only occurs during the terminal stream operation.<\/p>\n<div class=\"wp-block-syntaxhighlighter-code \">\n<pre class=\"brush: java; title: ; notranslate\" title=\"\">\nnew BufferedReader(new InputStreamReader(inputStream)).lines()\n<\/pre>\n<\/div>\n<p>Now let us collect these and join them with a new-line character:<\/p>\n<div class=\"wp-block-syntaxhighlighter-code \">\n<pre class=\"brush: java; title: ; notranslate\" title=\"\">\nString csvAsString = new BufferedReader(new InputStreamReader(inputStream)).lines().collect(Collectors.joining(&quot;\\n&quot;));\n<\/pre>\n<\/div>\n<p>The <code>collect()<\/code> method performs a mutable reduction operation on the elements of this stream using a <code>Collector<\/code>.<\/p>\n<p>Now we will use the org.json.CDL class to convert this string representation of CSV to JSON:<\/p>\n<div class=\"wp-block-syntaxhighlighter-code \">\n<pre class=\"brush: java; title: ; notranslate\" title=\"\">\nString json = CDL.toJSONArray(csvAsString).toString();\n<\/pre>\n<\/div>\n<p>This produces a <code>JSONArray<\/code> of <code>JSONObjects<\/code> from a comma-delimited text string, using the first row as a source of names.<\/p>\n<p>Now we need to write this to a file. To do that we will use the <code>Files.write()<\/code>. <\/p>\n<div class=\"wp-block-syntaxhighlighter-code \">\n<pre class=\"brush: java; title: ; notranslate\" title=\"\">\nFiles.write(Path.of(&quot;src\/main\/resources\/output.json&quot;), json.getBytes(StandardCharsets.UTF_8));\n<\/pre>\n<\/div>\n<p>Below is the full source code for the java file:<\/p>\n<p><span style=\"text-decoration: underline\"><em>CsvToJson.java<\/em><\/span><\/p>\n<div class=\"wp-block-syntaxhighlighter-code \">\n<pre class=\"brush: java; title: ; notranslate\" title=\"\">\npackage org.javacodegeeks;\n\nimport org.json.CDL;\n\nimport java.io.BufferedReader;\nimport java.io.IOException;\nimport java.io.InputStream;\nimport java.io.InputStreamReader;\nimport java.nio.charset.StandardCharsets;\nimport java.nio.file.Files;\nimport java.nio.file.Path;\nimport java.util.stream.Collectors;\n\npublic class CsvToJson {\n\n    public static void main(String&#x5B;] args) {\n        InputStream inputStream = CsvToJson.class.getClassLoader().getResourceAsStream(&quot;input.csv&quot;);\n        String csvAsString = new BufferedReader(new InputStreamReader(inputStream)).lines().collect(Collectors.joining(&quot;\\n&quot;));\n        String json = CDL.toJSONArray(csvAsString).toString();\n        try {\n            Files.write(Path.of(&quot;src\/main\/resources\/output.json&quot;), json.getBytes(StandardCharsets.UTF_8));\n        } catch (IOException e) {\n            e.printStackTrace();\n        }\n    }\n}\n\n<\/pre>\n<\/div>\n<p>Now if you run this class a file (output.json) will be created in the src\/main\/resources folder. The content will be similar to the below:<\/p>\n<p><span style=\"text-decoration: underline\"><em>output.json<\/em><\/span><\/p>\n<div class=\"wp-block-syntaxhighlighter-code \">\n<pre class=\"brush: jscript; title: ; notranslate\" title=\"\">\n&#x5B;\n  {\n    &quot;First name&quot;: &quot;Tom&quot;,\n    &quot;Date of Birth&quot;: &quot;01-01-1966&quot;,\n    &quot;Gender&quot;: &quot;Male&quot;,\n    &quot;Surname&quot;: &quot;Cruise&quot;\n  },\n  {\n    &quot;First name&quot;: &quot;Shahrukh&quot;,\n    &quot;Date of Birth&quot;: &quot;02-02-1955&quot;,\n    &quot;Gender&quot;: &quot;Male&quot;,\n    &quot;Surname&quot;: &quot;Khan&quot;\n  }\n]\n<\/pre>\n<\/div>\n<h2 class=\"wp-block-heading\" id=\"h-4-json-to-csv\">4. JSON to CSV<\/h2>\n<p>In this section, we will see how to convert a JSON file to CSV format. First, we will create a sample input.json file in the resources folder:<\/p>\n<p><span style=\"text-decoration: underline\"><em>input.json<\/em><\/span><\/p>\n<div class=\"wp-block-syntaxhighlighter-code \">\n<pre class=\"brush: jscript; title: ; notranslate\" title=\"\">\n&#x5B;\n  {\n    &quot;First name&quot;: &quot;John&quot;,\n    &quot;Date of Birth&quot;: &quot;10-11-1999&quot;,\n    &quot;Gender&quot;: &quot;Male&quot;,\n    &quot;Surname&quot;: &quot;Dickson&quot;\n  },\n  {\n    &quot;First name&quot;: &quot;Milena&quot;,\n    &quot;Date of Birth&quot;: &quot;20-04-1975&quot;,\n    &quot;Gender&quot;: &quot;Female&quot;,\n    &quot;Surname&quot;: &quot;Trump&quot;\n  }\n]\n<\/pre>\n<\/div>\n<p>Now let us look at the java code to convert this JSON file to CSV. First, we will read the file as we did before:<\/p>\n<div class=\"wp-block-syntaxhighlighter-code \">\n<pre class=\"brush: java; title: ; notranslate\" title=\"\">\nInputStream inputStream = JsonToCsv.class.getClassLoader().getResourceAsStream(&quot;input.json&quot;);\n<\/pre>\n<\/div>\n<p>Now we will convert this stream to JSONArray object:<\/p>\n<div class=\"wp-block-syntaxhighlighter-code \">\n<pre class=\"brush: java; title: ; notranslate\" title=\"\">\nJSONArray jsonArray = new JSONArray(new JSONTokener(inputStream));\n<\/pre>\n<\/div>\n<p>A <code>JSONTokener<\/code> takes a source string and extracts characters and tokens from it. It is used by the <code>JSONObject<\/code> and <code>JSONArray<\/code> constructors to parse JSON source strings. Now we will use CDL.toString() method which produces a comma delimited text from a <code>JSONArrayObjects<\/code>. The first row will be a list of names obtained by inspecting the first <code>JSONObject<\/code>. Now let us write this in a CSV file:<\/p>\n<div class=\"wp-block-syntaxhighlighter-code \">\n<pre class=\"brush: java; title: ; notranslate\" title=\"\">\nFiles.write(Path.of(&quot;src\/main\/resources\/output.csv&quot;), CDL.toString(jsonArray).getBytes(StandardCharsets.UTF_8));\n<\/pre>\n<\/div>\n<p>Below is the full source code of converting a JSON file to CSV format:<\/p>\n<p><span style=\"text-decoration: underline\"><em>JsonToCsv.java<\/em><\/span><\/p>\n<div class=\"wp-block-syntaxhighlighter-code \">\n<pre class=\"brush: java; title: ; notranslate\" title=\"\">\npackage org.javacodegeeks;\n\nimport org.json.CDL;\nimport org.json.JSONArray;\nimport org.json.JSONTokener;\n\nimport java.io.IOException;\nimport java.io.InputStream;\nimport java.nio.charset.StandardCharsets;\nimport java.nio.file.Files;\nimport java.nio.file.Path;\n\npublic class JsonToCsv {\n\n    public static void main(String&#x5B;] args) {\n        InputStream inputStream = JsonToCsv.class.getClassLoader().getResourceAsStream(&quot;input.json&quot;);\n        JSONArray jsonArray = new JSONArray(new JSONTokener(inputStream));\n        try {\n            Files.write(Path.of(&quot;src\/main\/resources\/output.csv&quot;), CDL.toString(jsonArray).getBytes(StandardCharsets.UTF_8));\n        } catch (IOException e) {\n            e.printStackTrace();\n        }\n    }\n}\n\n<\/pre>\n<\/div>\n<h2 class=\"wp-block-heading\" id=\"h-5-summary\">5. Summary<\/h2>\n<p>In this article, we looked at what are CSV and JSON files and then how to convert them. First, we looked at a simple way of converting a CSV file to a JSON format and then vice-versa. Please note that there are lot more libraries that we can use to achieve the same result but I find org.json.json quite easy and straightforward. Also, this example is for a very simple case &#8211; If the input file is very big then we can&#8217;t read the whole file in memory and we need to rethink our solution. <\/p>\n<h2 class=\"wp-block-heading\" id=\"h-6-download\">6. Download<\/h2>\n<p>This was an example of converting a CSV file to JSON and vice-versa in java.<\/p>\n<div class=\"download\"><strong>Download<\/strong><br \/>\nYou can download the full source code of this example here: <a href=\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2022\/05\/JavaCodeGeeks-1.zip\"><strong>Convert CSV to Json using Java<\/strong><\/a><\/div>\n","protected":false},"excerpt":{"rendered":"<p>1. Introduction A comma-separated values (CSV) file is a delimited text file that uses a comma to separate values. Each line of the file is a data record. Each record consists of one or more fields, separated by commas. The use of the comma as a field separator is the source of the name for &hellip;<\/p>\n","protected":false},"author":34,"featured_media":1211,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[22],"tags":[728],"class_list":["post-112388","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-json","tag-csv"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v26.5 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>Convert CSV to Json using Java - Java Code Geeks<\/title>\n<meta name=\"description\" content=\"In this section, we will see how to convert a CSV file to JSON. First, we will create a test CSV file in the resource folder. The resource...\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/examples.javacodegeeks.com\/convert-csv-to-json-using-java\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Convert CSV to Json using Java - Java Code Geeks\" \/>\n<meta property=\"og:description\" content=\"In this section, we will see how to convert a CSV file to JSON. First, we will create a test CSV file in the resource folder. The resource...\" \/>\n<meta property=\"og:url\" content=\"https:\/\/examples.javacodegeeks.com\/convert-csv-to-json-using-java\/\" \/>\n<meta property=\"og:site_name\" content=\"Examples Java Code Geeks\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/javacodegeeks\" \/>\n<meta property=\"article:published_time\" content=\"2022-05-27T08:00:00+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2012\/12\/json-logo.jpg\" \/>\n\t<meta property=\"og:image:width\" content=\"150\" \/>\n\t<meta property=\"og:image:height\" content=\"150\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/jpeg\" \/>\n<meta name=\"author\" content=\"Mohammad Meraj Zia\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@javacodegeeks\" \/>\n<meta name=\"twitter:site\" content=\"@javacodegeeks\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Mohammad Meraj Zia\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"6 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\/\/examples.javacodegeeks.com\/convert-csv-to-json-using-java\/#article\",\"isPartOf\":{\"@id\":\"https:\/\/examples.javacodegeeks.com\/convert-csv-to-json-using-java\/\"},\"author\":{\"name\":\"Mohammad Meraj Zia\",\"@id\":\"https:\/\/examples.javacodegeeks.com\/#\/schema\/person\/442b4f9b8a4aa7e12376464fc354f8ed\"},\"headline\":\"Convert CSV to Json using Java\",\"datePublished\":\"2022-05-27T08:00:00+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/examples.javacodegeeks.com\/convert-csv-to-json-using-java\/\"},\"wordCount\":989,\"commentCount\":0,\"publisher\":{\"@id\":\"https:\/\/examples.javacodegeeks.com\/#organization\"},\"image\":{\"@id\":\"https:\/\/examples.javacodegeeks.com\/convert-csv-to-json-using-java\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2012\/12\/json-logo.jpg\",\"keywords\":[\"CSV\"],\"articleSection\":[\"json\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\/\/examples.javacodegeeks.com\/convert-csv-to-json-using-java\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/examples.javacodegeeks.com\/convert-csv-to-json-using-java\/\",\"url\":\"https:\/\/examples.javacodegeeks.com\/convert-csv-to-json-using-java\/\",\"name\":\"Convert CSV to Json using Java - Java Code Geeks\",\"isPartOf\":{\"@id\":\"https:\/\/examples.javacodegeeks.com\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\/\/examples.javacodegeeks.com\/convert-csv-to-json-using-java\/#primaryimage\"},\"image\":{\"@id\":\"https:\/\/examples.javacodegeeks.com\/convert-csv-to-json-using-java\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2012\/12\/json-logo.jpg\",\"datePublished\":\"2022-05-27T08:00:00+00:00\",\"description\":\"In this section, we will see how to convert a CSV file to JSON. First, we will create a test CSV file in the resource folder. The resource...\",\"breadcrumb\":{\"@id\":\"https:\/\/examples.javacodegeeks.com\/convert-csv-to-json-using-java\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/examples.javacodegeeks.com\/convert-csv-to-json-using-java\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/examples.javacodegeeks.com\/convert-csv-to-json-using-java\/#primaryimage\",\"url\":\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2012\/12\/json-logo.jpg\",\"contentUrl\":\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2012\/12\/json-logo.jpg\",\"width\":150,\"height\":150},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/examples.javacodegeeks.com\/convert-csv-to-json-using-java\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/examples.javacodegeeks.com\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Java Development\",\"item\":\"https:\/\/examples.javacodegeeks.com\/category\/java-development\/\"},{\"@type\":\"ListItem\",\"position\":3,\"name\":\"Core Java\",\"item\":\"https:\/\/examples.javacodegeeks.com\/category\/java-development\/core-java\/\"},{\"@type\":\"ListItem\",\"position\":4,\"name\":\"json\",\"item\":\"https:\/\/examples.javacodegeeks.com\/category\/java-development\/core-java\/json\/\"},{\"@type\":\"ListItem\",\"position\":5,\"name\":\"Convert CSV to Json using Java\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/examples.javacodegeeks.com\/#website\",\"url\":\"https:\/\/examples.javacodegeeks.com\/\",\"name\":\"Java Code Geeks\",\"description\":\"Java Examples and Code Snippets\",\"publisher\":{\"@id\":\"https:\/\/examples.javacodegeeks.com\/#organization\"},\"alternateName\":\"JCG\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/examples.javacodegeeks.com\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Organization\",\"@id\":\"https:\/\/examples.javacodegeeks.com\/#organization\",\"name\":\"Exelixis Media P.C.\",\"url\":\"https:\/\/examples.javacodegeeks.com\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/examples.javacodegeeks.com\/#\/schema\/logo\/image\/\",\"url\":\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2022\/06\/exelixis-logo.png\",\"contentUrl\":\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2022\/06\/exelixis-logo.png\",\"width\":864,\"height\":246,\"caption\":\"Exelixis Media P.C.\"},\"image\":{\"@id\":\"https:\/\/examples.javacodegeeks.com\/#\/schema\/logo\/image\/\"},\"sameAs\":[\"https:\/\/www.facebook.com\/javacodegeeks\",\"https:\/\/x.com\/javacodegeeks\"]},{\"@type\":\"Person\",\"@id\":\"https:\/\/examples.javacodegeeks.com\/#\/schema\/person\/442b4f9b8a4aa7e12376464fc354f8ed\",\"name\":\"Mohammad Meraj Zia\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/examples.javacodegeeks.com\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2020\/06\/IMG-20200324-WA0003-96x96.jpg\",\"contentUrl\":\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2020\/06\/IMG-20200324-WA0003-96x96.jpg\",\"caption\":\"Mohammad Meraj Zia\"},\"description\":\"Senior Java Developer\",\"sameAs\":[\"http:\/\/www.javacodegeeks.com\/\"],\"url\":\"https:\/\/examples.javacodegeeks.com\/author\/mohammad-zia\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Convert CSV to Json using Java - Java Code Geeks","description":"In this section, we will see how to convert a CSV file to JSON. First, we will create a test CSV file in the resource folder. The resource...","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/examples.javacodegeeks.com\/convert-csv-to-json-using-java\/","og_locale":"en_US","og_type":"article","og_title":"Convert CSV to Json using Java - Java Code Geeks","og_description":"In this section, we will see how to convert a CSV file to JSON. First, we will create a test CSV file in the resource folder. The resource...","og_url":"https:\/\/examples.javacodegeeks.com\/convert-csv-to-json-using-java\/","og_site_name":"Examples Java Code Geeks","article_publisher":"https:\/\/www.facebook.com\/javacodegeeks","article_published_time":"2022-05-27T08:00:00+00:00","og_image":[{"width":150,"height":150,"url":"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2012\/12\/json-logo.jpg","type":"image\/jpeg"}],"author":"Mohammad Meraj Zia","twitter_card":"summary_large_image","twitter_creator":"@javacodegeeks","twitter_site":"@javacodegeeks","twitter_misc":{"Written by":"Mohammad Meraj Zia","Est. reading time":"6 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/examples.javacodegeeks.com\/convert-csv-to-json-using-java\/#article","isPartOf":{"@id":"https:\/\/examples.javacodegeeks.com\/convert-csv-to-json-using-java\/"},"author":{"name":"Mohammad Meraj Zia","@id":"https:\/\/examples.javacodegeeks.com\/#\/schema\/person\/442b4f9b8a4aa7e12376464fc354f8ed"},"headline":"Convert CSV to Json using Java","datePublished":"2022-05-27T08:00:00+00:00","mainEntityOfPage":{"@id":"https:\/\/examples.javacodegeeks.com\/convert-csv-to-json-using-java\/"},"wordCount":989,"commentCount":0,"publisher":{"@id":"https:\/\/examples.javacodegeeks.com\/#organization"},"image":{"@id":"https:\/\/examples.javacodegeeks.com\/convert-csv-to-json-using-java\/#primaryimage"},"thumbnailUrl":"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2012\/12\/json-logo.jpg","keywords":["CSV"],"articleSection":["json"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/examples.javacodegeeks.com\/convert-csv-to-json-using-java\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/examples.javacodegeeks.com\/convert-csv-to-json-using-java\/","url":"https:\/\/examples.javacodegeeks.com\/convert-csv-to-json-using-java\/","name":"Convert CSV to Json using Java - Java Code Geeks","isPartOf":{"@id":"https:\/\/examples.javacodegeeks.com\/#website"},"primaryImageOfPage":{"@id":"https:\/\/examples.javacodegeeks.com\/convert-csv-to-json-using-java\/#primaryimage"},"image":{"@id":"https:\/\/examples.javacodegeeks.com\/convert-csv-to-json-using-java\/#primaryimage"},"thumbnailUrl":"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2012\/12\/json-logo.jpg","datePublished":"2022-05-27T08:00:00+00:00","description":"In this section, we will see how to convert a CSV file to JSON. First, we will create a test CSV file in the resource folder. The resource...","breadcrumb":{"@id":"https:\/\/examples.javacodegeeks.com\/convert-csv-to-json-using-java\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/examples.javacodegeeks.com\/convert-csv-to-json-using-java\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/examples.javacodegeeks.com\/convert-csv-to-json-using-java\/#primaryimage","url":"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2012\/12\/json-logo.jpg","contentUrl":"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2012\/12\/json-logo.jpg","width":150,"height":150},{"@type":"BreadcrumbList","@id":"https:\/\/examples.javacodegeeks.com\/convert-csv-to-json-using-java\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/examples.javacodegeeks.com\/"},{"@type":"ListItem","position":2,"name":"Java Development","item":"https:\/\/examples.javacodegeeks.com\/category\/java-development\/"},{"@type":"ListItem","position":3,"name":"Core Java","item":"https:\/\/examples.javacodegeeks.com\/category\/java-development\/core-java\/"},{"@type":"ListItem","position":4,"name":"json","item":"https:\/\/examples.javacodegeeks.com\/category\/java-development\/core-java\/json\/"},{"@type":"ListItem","position":5,"name":"Convert CSV to Json using Java"}]},{"@type":"WebSite","@id":"https:\/\/examples.javacodegeeks.com\/#website","url":"https:\/\/examples.javacodegeeks.com\/","name":"Java Code Geeks","description":"Java Examples and Code Snippets","publisher":{"@id":"https:\/\/examples.javacodegeeks.com\/#organization"},"alternateName":"JCG","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/examples.javacodegeeks.com\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/examples.javacodegeeks.com\/#organization","name":"Exelixis Media P.C.","url":"https:\/\/examples.javacodegeeks.com\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/examples.javacodegeeks.com\/#\/schema\/logo\/image\/","url":"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2022\/06\/exelixis-logo.png","contentUrl":"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2022\/06\/exelixis-logo.png","width":864,"height":246,"caption":"Exelixis Media P.C."},"image":{"@id":"https:\/\/examples.javacodegeeks.com\/#\/schema\/logo\/image\/"},"sameAs":["https:\/\/www.facebook.com\/javacodegeeks","https:\/\/x.com\/javacodegeeks"]},{"@type":"Person","@id":"https:\/\/examples.javacodegeeks.com\/#\/schema\/person\/442b4f9b8a4aa7e12376464fc354f8ed","name":"Mohammad Meraj Zia","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/examples.javacodegeeks.com\/#\/schema\/person\/image\/","url":"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2020\/06\/IMG-20200324-WA0003-96x96.jpg","contentUrl":"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2020\/06\/IMG-20200324-WA0003-96x96.jpg","caption":"Mohammad Meraj Zia"},"description":"Senior Java Developer","sameAs":["http:\/\/www.javacodegeeks.com\/"],"url":"https:\/\/examples.javacodegeeks.com\/author\/mohammad-zia\/"}]}},"_links":{"self":[{"href":"https:\/\/examples.javacodegeeks.com\/wp-json\/wp\/v2\/posts\/112388","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/examples.javacodegeeks.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/examples.javacodegeeks.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/examples.javacodegeeks.com\/wp-json\/wp\/v2\/users\/34"}],"replies":[{"embeddable":true,"href":"https:\/\/examples.javacodegeeks.com\/wp-json\/wp\/v2\/comments?post=112388"}],"version-history":[{"count":0,"href":"https:\/\/examples.javacodegeeks.com\/wp-json\/wp\/v2\/posts\/112388\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/examples.javacodegeeks.com\/wp-json\/wp\/v2\/media\/1211"}],"wp:attachment":[{"href":"https:\/\/examples.javacodegeeks.com\/wp-json\/wp\/v2\/media?parent=112388"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/examples.javacodegeeks.com\/wp-json\/wp\/v2\/categories?post=112388"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/examples.javacodegeeks.com\/wp-json\/wp\/v2\/tags?post=112388"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}