0

Having trouble exporting a json string to a text file -

> tester <- list(10, 20) %>% 
          toJSON(. , auto_unbox = T)
> write.table(tester, file = "JSONfile.txt", sep = "")
Error in as.data.frame.default(x[[i]], optional = TRUE, stringsAsFactors = stringsAsFactors) : 
  cannot coerce class ""json"" to a data.frame

is there an alternative way to exporting the JSON into a text?

S31
  • 904
  • 2
  • 9
  • 21
  • 1
    you can try link https://stackoverflow.com/questions/24662303/saving-a-json-object-to-file-json?utm_medium=organic&utm_source=google_rich_qa&utm_campaign=google_rich_qa – caot May 25 '18 at 15:02
  • Cool - write(tester, file = "tester.txt") works! – S31 May 25 '18 at 16:30

1 Answers1

0

maybe try

sink("./JSONfile.txt")
list(10, 20) %>% toJSON(. , auto_unbox = T) %>% cat
sink()
Ma Ba
  • 148
  • 9