0

I'm trying to convert the json object into a CSV file using java.

My json :

{"Type":"Camera","modelName":"Alpha","asinno":"B0YUSAWZ"} 

Expected O/p:

Type,modelName,asinno
Camera,Alpha,B0YUSAWZ

I have tried using "CDL.toString()", but toString is expecting a json array but not a simple json object. How can we deal with simple json ?

Can anyone please help me out...

0

1 Answer 1

0

JSON isn't really a (CSV) table format. So I guess you'll have to come up with something yourself. (If you don't already have,) you can gain Object-access to your JSON. You'll also need a CSVWriter. You can take the OpenCSV library or write a simple one yourself (that just concats the strings with commas inbetween).

Here is some logic

csvWriter = new CSVWriter(...)
json = parseJson(...)

//header line
for each key in json
    csvWriter.write(key)

csvWriter.nextLine()

//value line
for each key in json
    value = json[key]
    csvWriter.write(value)

csvString = csvWriter.asString()
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.