0

Is there any way to convert multiple JSON files into one CSV-file ?

My JSON file is like this:

{
  "Title" : {
      "name" : "ABC",
      "id" : "1",
      "job": "Teacher"    
      },
      "Circle":{
                "area":"2R"
        },
        "Triangle":{
                "length":"45"
        }
}

If you will see, this JSON has 3 roots and different elements under each root. How to convert this JSON to CSV so that it can be opened in excel and can be viewed as follows:

Title
Name  ABC
id    1
job   Teacher
Circle
area  2r
Triangle
length  45

Can someone please suggest?

3
  • I suggest you to use a JSON parser Commented Jun 3, 2015 at 9:42
  • I can't think of a use-case for this. You'd lose the structure of your data. You won't be able to re-create the JSON from the CSV. Commented Jun 3, 2015 at 9:49
  • This is going to be quite silly I just can't help myself. Have you thought about jsonString.replaceAll("[\\\"\\{\\}\\:\\,]"," "); because that produces something very similar to your CSV. Commented Jun 3, 2015 at 10:31

2 Answers 2

1

It would say that you should first parse you JSON with something like Jackson, and then you can write down a CSV file by using their extension. That's an option.

Other way might be to use an external tool to do the conversion, such as json2csv.

Hope it helps!

Sign up to request clarification or add additional context in comments.

Comments

1

There is a library json2flat. It converted your json

{
  "Title" : {
      "name" : "ABC",
      "id" : "1",
      "job": "Teacher"    
      },
      "Circle":{
                "area":"2R"
        },
        "Triangle":{
                "length":"45"
        }
}

to the following

/Title/name,/Title/id,/Title/job,/Circle/area,/Triangle/length
"ABC","1","Teacher","2R","45" 

Hope it helps. After all it depends upon users how they want to interpret it.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.