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?
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.
A sample file is(file.txt):
{"ID":"abc","mscore":45,"cscore":42,"grade":"A"}
{"ID":"xyz","mscore":41"cscore":35,"grade":"B"}
{"ID":"pqr","mscore":37"cscore":41,"grade":"B"}
{"ID":"mno","mscore":32,"cscore":29,"grade":"C"}
I want to convert this to (file.csv): where score=mscore+cscore
ID score grade
"abc" 87 A
"xyz" 76 B
"pqr" 78 B
"mno" 61 C
-------- UPDATE ---------
I created a class Student
public class Student{
String ID;
int mscore;
int cscore;
String grade;
}
I used the below code snippet to read the text file of JSON objects and store the data in a studentList
.
S3Object s3Object = s3Client.getObject(new GetObjectRequest(s3BucketName, fileKey));
S3ObjectInputStream s3Stream = s3Object.getObjectContent();
BufferedReader reader = new BufferedReader(new InputStreamReader(s3Stream, StringUtils.UTF8));
List<Student> studentList=null;
while ((line = reader.readLine()) != null) {
Student student = objectMapper.readValue(line, Student.class);
studentList.add(student);
}
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.