How to convert JSON into CSV in R programming

0 votes

This is my JSON format:

{"abc":
  {
    "123":[45600],
    "378":[78689],
    "343":[23456]
  }
}

I want to convert this JSON format to CSV file in R.

CSV format :

 ds      y
123  45600
378  78689
343  23456

I'm using R library rjson to do this.. 

I tried this:

jsonFile <- fromJSON(file=fileName)
json_data_frame <- as.data.frame(jsonFile)

but it's not working out.

Jan 24, 2019 in Data Analytics by Tyrion anex
• 8,700 points
6,989 views

1 answer to this question.

0 votes

Use the jsonlite::fromJSON to read the data into a list, but you'll have to pull it apart to assemble it into a data.frame:

abc <- jsonlite::fromJSON('{"abc":
{
    "123":[45600],
    "378":[78689],
    "343":[23456]
    }
}')


abc <- data.frame(ds = names(abc[[1]]), 
                  y = unlist(abc[[1]]), stringsAsFactors = FALSE)

abc
#>      ds     y
#> 123 123 45600
#> 378 378 78689
#> 343 343 23456
answered Jan 24, 2019 by Sophie may
• 10,620 points

Related Questions In Data Analytics

0 votes
1 answer

How to convert a text mining termDocumentMatrix into excel or csv in R?

By assuming that all the values are ...READ MORE

answered Apr 5, 2018 in Data Analytics by DeepCoder786
• 1,720 points
1,838 views
0 votes
1 answer

How do I convert data frame to csv file in R?

Hey @Ali, its very simple one line ...READ MORE

answered Nov 21, 2018 in Data Analytics by Maverick
• 10,840 points
2,366 views
+1 vote
1 answer
0 votes
2 answers

how to convert a data frame into a list in R

Convert whole data frame into a list?? ...READ MORE

answered Sep 4, 2019 in Data Analytics by anonymous
• 33,030 points
1,235 views
+10 votes
3 answers

Which is a better initiative to learn data science: Python or R?

Well it truly depends on your requirement, If ...READ MORE

answered Aug 9, 2018 in Data Analytics by Abhi
• 3,720 points
1,502 views
+1 vote
1 answer

Error saying "vector size cannot be NA" when using R with data mining

You can use the removesparseterm function.  Removes sparse ...READ MORE

answered Nov 15, 2018 in Data Analytics by Maverick
• 10,840 points
4,697 views
+1 vote
2 answers
0 votes
1 answer

Trying to find frequent itemsets of a data set using arules package

Try replacing ID <- c("A123","A123","A123","A123","B456","B456","B456") item <- c("bread", "butter", "milk", ...READ MORE

answered Nov 15, 2018 in Data Analytics by Maverick
• 10,840 points
751 views
0 votes
1 answer

How to remove HTML tags from string in R Programming?

Try this simple code to remove the <br ...READ MORE

answered Feb 1, 2019 in Data Analytics by Sophie may
• 10,620 points
4,596 views
+1 vote
1 answer

How to create a 2D array of vectors of different lengths in R programming?

You can try making a list of matrices ...READ MORE

answered Feb 1, 2019 in Data Analytics by Sophie may
• 10,620 points
1,634 views
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP