1

I need to convert a complex .json file in a csv in a java evironment. I've already seen it Javascript / convert json to csv and Converting JSON to XLS/CSV in Java and Convert JSON format to CSV format for MS Excel and the applications developed in it, but they didn't work with my file, that is like this example:

{
    "metadata": {"result_type": "recent", "iso_language_code": "it"}, 
    "created_at": "Thu Apr 04 16: 48: 29 +0000 2013", 
    "user": {
        "id": "integer", 
        "id_str": "id_str", 
        "name": "a name and a surname", 
        "screen_name": "ascreenname", 
        "location": "Roma", 
        "description": "some description ", 
        "url": "some url", 
        "entities": {
            "url": {
                "urls": [{
                    "url": "other url", 
                    "expanded_url": null, 
                    "indices": [0, 39]
                }]
            }, 
            "description": {"urls": []}
        }, 
        "notifications": null
    }, 
    "geo": null, 
    "coordinates": null, 
    "place": null, 
    "contributors": null, 
    "entities": {
        "hashtags": [
            {"text": "text", "indices": [29, 35]}, 
            {"text": "text", "indices": [36, 52]}, 
            {"text": "roma", "indices": [53, 58]}, 
            {"text": "ostiense", "indices": [59, 68]}, 
            {"text": "text", "indices": [69, 79]}, 
            {"text": "text", "indices": [80, 92]}, 
            {"text": "text", "indices": [93, 99]}
        ], 
        "urls": [
            {"url": "an url", "expanded_url": "an url", "indices": [101, 123]}
        ], 
        "user_mentions": []
    }, 
    "lang": "it"
}
Community
  • 1
  • 1
user2252332
  • 11
  • 1
  • 2
  • 1
    Those questions you reference should be enough to solve your particular problem, with some customization. If you fail your customization effort, then show us the code for more help. – Martin Wickman Apr 13 '13 at 13:16
  • 2
    json data structure you have given is not directly mappable to csv. You may have to parse and construct a suitable object graph and then write back a csv, say using openCSV. – Jayan Apr 13 '13 at 13:16
  • Don't post a wall of code as an answer. Edit your answer instead, and only include relevant sections of the code. Nobody wants to read through a ton of code to figure out where your problem is. – NullUserException Apr 17 '13 at 19:50
  • possible duplicate of [Convert java Object to CSV](http://stackoverflow.com/questions/11791353/convert-java-object-to-csv) – 0x90 Apr 17 '13 at 20:05
  • CSV is intended for flat rows of data, not for structured data. You need to figure out how to flatten your JSON object into a single row of values. – David R Tribble Apr 17 '13 at 21:22

0 Answers0