title: How to read a JSON file stored in Amazon S3 in java and convert it to CSV
body: <p>I have a text file present in an Amazon S3 bucket containing JSON objects which I need to parse and extract information out of it. How do I do that in java?</p>
  <p>I am not able to do that in Java. I just need to be able to parse this JSON file and convert to csv and upload this CSV file to Amazon S3.</p>
  <p>A sample file is(file.txt):</p>
  <pre><code>{&quot;ID&quot;:&quot;abc&quot;,&quot;mscore&quot;:45,&quot;cscore&quot;:42,&quot;grade&quot;:&quot;A&quot;}
  {&quot;ID&quot;:&quot;xyz&quot;,&quot;mscore&quot;:41&quot;cscore&quot;:35,&quot;grade&quot;:&quot;B&quot;}
  {&quot;ID&quot;:&quot;pqr&quot;,&quot;mscore&quot;:37&quot;cscore&quot;:41,&quot;grade&quot;:&quot;B&quot;}
  {&quot;ID&quot;:&quot;mno&quot;,&quot;mscore&quot;:32,&quot;cscore&quot;:29,&quot;grade&quot;:&quot;C&quot;}
  </code></pre>
  <p>I want to convert this to (file.csv): where <code>score=mscore+cscore</code></p>
  <pre><code>ID      score      grade
  &quot;abc&quot;   87         A
  &quot;xyz&quot;   76         B
  &quot;pqr&quot;   78         B
  &quot;mno&quot;   61         C
  </code></pre>
  <p>-------- UPDATE ---------</p>
  <p>I created a class Student</p>
  <pre><code>public class Student{
  String ID;
  int mscore;
  int cscore;
  String grade;
  }
  </code></pre>
  <p>I used the below code snippet to read the text file of JSON objects and store the data in a <code>studentList</code>.</p>
  <pre><code>S3Object s3Object = s3Client.getObject(new GetObjectRequest(s3BucketName, fileKey)); 
  S3ObjectInputStream s3Stream = s3Object.getObjectContent(); 
  BufferedReader reader = new BufferedReader(new InputStreamReader(s3Stream, StringUtils.UTF8)); 
  List&lt;Student&gt; studentList=null; 
  while ((line = reader.readLine()) != null) {
    Student student = objectMapper.readValue(line, Student.class);
    studentList.add(student);
  }
  </code></pre>
  <p>However, i cannot figure out how to convert this list to a CSV file and upload it to s3. I do not want to store file locally.</p>