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 in Data Analytics by Tyrion anex
• 8,310 points
848 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 by Sophie may
• 9,870 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
173 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,040 points
85 views
0 votes
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 in Data Analytics by anonymous
• 32,260 points
56 views
0 votes
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,040 points
576 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,040 points
46 views
0 votes
1 answer

Error saying "Error in df$item : object of type 'closure' is not subsettable" when trying to use arules package

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

answered Nov 15, 2018 in Data Analytics by Maverick
• 10,040 points
197 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 in Data Analytics by Sophie may
• 9,870 points
490 views
0 votes
1 answer