retrieve jsonfile with financial data using R in data frame

84 Views Asked by At

So, here json file https://api.coindesk.com/v1/bpi/currentprice/USD.json I parse json in this way

library("rjson")
json_file <- "https://api.coindesk.com/v1/bpi/currentprice/USD.json"
json_data <- fromJSON(paste(readLines(json_file), collapse=""))

as output i get

$time
$time$updated
[1] "Sep 16, 2018 11:35:00 UTC"

$time$updatedISO
[1] "2018-09-16T11:35:00+00:00"

$time$updateduk
[1] "Sep 16, 2018 at 12:35 BST"


$disclaimer
[1] "This data was produced from the CoinDesk Bitcoin Price Index (USD). Non-USD currency data converted using hourly conversion rate from openexchangerates.org"

$bpi
$bpi$USD
$bpi$USD$code
[1] "USD"

$bpi$USD$rate
[1] "6,497.5088"

$bpi$USD$description
[1] "United States Dollar"

$bpi$USD$rate_float
[1] 6497.509

I want get structured format. I as output must be

   time.updated            time.updatedISO   time.updateduk X.bpi.USD.rate X.bpi.USD.rate_float
1 16.09.2018 11:35 16.09.2018  11:35:00+00:00 16.09.2018 12:35     6,497.5088             6497.509

How parse in this format

1

There are 1 best solutions below

0
On

I would put it in a data.frame like this:

 x = data.frame(json_data$time$updated,json_data$time$updatedISO,json_data$time$updateduk,json_data$bpi$USD)

and then you can do print(x)