How do I convert a JSON file to a CSV file, or some other well-formatted file that is readable to R?
-
-
Answer:
This is super easy to do in Python. Try something like: import json objects = json.load(open('filename')) s = '' for obj in objects: # This depends on the json file... but something like: s += ', '.join(obj) s += '\n' f = open('out.csv','w') f.write(s) f.close()
Julius Bier Kirkegaard at Quora Visit the source
Other answers
I'm not sure if I understand the question. It is easy to load the json in R. Can you give a bit of detail?
Ricardo Vladimiro
If you do not want to use a script, you can try http://openrefine.org/ (formerly Google Refine). It can read Json and export the data to CSV. See http://googlerefine.blogspot.co.il/2011/10/parse-mark-up-language-json-html-xml.html for the input part, and http://enipedia.tudelft.nl/wiki/OpenRefine_Tutorial for the output part.
Yuval Feinstein
Using Pig, you can load your json data using JsonLoader (http://help.mortardata.com/reference/loading_and_storing_data/JSON), and store is out using PigStorage or CSVExcelStorage (http://help.mortardata.com/reference/loading_and_storing_data/CSV). my_data = LOAD 'path/to/json/file' USING org.apache.pig.piggybank.storage.JsonLoader(); data = STORE result INTO 'path/to/output' USING org.apache.pig.piggybank.storage.CSVExcelStorage( ',', 'YES_MULTILINE', 'WINDOWS', 'WRITE_OUTPUT_HEADER' ); The output will be in part files so you'll want to concat and rename them with a csv extension.
Cat Miller
By doing computer programming.
Joe Wezorek
JASON --> R --> CSV wouldn't be difficult. You may find the following package useful - https://github.com/jeroenooms/jsonlite.
Jaehyeon Kim
The rjsonio package in R handles json formatted files. No need for any intermediate steps. http://cran.r-project.org/web/packages/RJSONIO/index.html
Phillip Middleton
Here is a command line tool to convert JSON to csv https://github.com/jehiah/json2csv
Sherri Douville
you can convert your json file or text to CSV using this free services and then upload import it to R http://fileformat-converter.com
Udit Saini
JSON is well supported in R. I would simply deal with the JSON directly. An example: library(jsonlite) json.data <- fromJSON("./mydata.json")
James McInnes
Related Q & A:
- How do I convert a PDF file to PDF/A in Delphi?Best solution by softwarerecs.stackexchange.com
- How can I convert a string number to a number in Perl?Best solution by Stack Overflow
- How can I burn a .rmvb file onto a DVD for viewing on a regular DVD player?Best solution by Yahoo! Answers
- How do I get a video file off a sony video camera disk?Best solution by Yahoo! Answers
- How to convert a .DMG file into a .EXE?Best solution by answers.yahoo.com
Just Added Q & A:
- How many active mobile subscribers are there in China?Best solution by Quora
- How to find the right vacation?Best solution by bookit.com
- How To Make Your Own Primer?Best solution by thekrazycouponlady.com
- How do you get the domain & range?Best solution by ChaCha
- How do you open pop up blockers?Best solution by Yahoo! Answers
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.