How to convert Json to CSV or Excel?

Convert JSON format to CSV format for MS Excel

  • I received a JSON file but don't know how to read it. Is there a converter where I can produce a nice CSV file so it can be loaded into MS Excel? I don't understand JSON, so it would be awesome if someone wrote a script or link me to one that would do the job. I found something close at http://json.bloople.net but, unfortunately, it's JSON to HTML. Edit: jsonformat.com gets even closer, however it's still not CSV.

  • Answer:

    I'm not sure what your doing, but this will go from JSON to CSV using JavaScript. This is using http://www.json.org/js.html, just download JSON.js into the same folder you save the code below, and it will parse the static JSON value in "json3" into CSV and prompt you to download/open in excel. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <title>JSON to CSV</title> <script src="scripts/json.js" type="text/javascript"></script> <script type="text/javascript"> var json3 = { "d": "[{\"Id\":1,\"UserName\":\"Sam Smith\"},{\"Id\":2,\"UserName\":\"Fred Frankly\"},{\"Id\":1,\"UserName\":\"Zachary Zupers\"}]" } DownloadJSON2CSV(json3.d); function DownloadJSON2CSV(objArray) { var array = typeof objArray != 'object' ? JSON.parse(objArray) : objArray; var str = ''; for (var i = 0; i < array.length; i++) { var line = ''; for (var index in array[i]) { line += array[i][index] + ','; } line.slice(0,line.Length-1); str += line + '\r\n'; } window.open( "data:text/csv;charset=utf-8," + escape(str)) } </script> </head> <body> <h1>This page does nothing....</h1> </body> </html>

stockoverflow at Stack Overflow Visit the source

Was this solution helpful to you?

Other answers

use python will be one easy way to achieve that. I encourage you google first. (because I found one on google) following is an example: http://stackoverflow.com/questions/1871524/convert-from-json-to-csv-using-python

chinuy

Here are some example excel downloads with json excel connversion capabilities. http://ramblings.mcpher.com/Home/excelquirks/json

user400514

Just Added Q & A:

Find solution

For every problem there is a solution! Proved by Solucija.

  • Got an issue and looking for advice?

  • Ask Solucija to search every corner of the Web for help.

  • Get workable solutions and helpful tips in a moment.

Just ask Solucija about an issue you face and immediately get a list of ready solutions, answers and tips from other Internet users. We always provide the most suitable and complete answer to your question at the top, along with a few good alternatives below.