I'm been working with JSON response from API, and have been able to return the data in a format that looks very JSON (which is good) and not struggling to get into DataFrame. Here is the code:
`message(typeof((results_response)))`
# character
`message(length((results_response)))`
# 1
`message(results_response)`
# {"central_time":{"0":"2020-04-06 15:47:00","1":"2020-04-06 15:47:15"},"Va_V":{"0":286.032,"1":286.207}}
The goal would not hard coding the keys, because there could be other responses when different keys. thank you!
You could try using the tidyjson
package.
library(tidyjson, warn.conflicts = FALSE)
results_response <- '{"central_time":{"0":"2020-04-06 15:47:00","1":"2020-04-06 15:47:15"},"Va_V":{"0":286.032,"1":286.207}}'
spread_all(results_response)
#> # A tbl_json: 1 x 5 tibble with a "JSON" attribute
#> `attr(., "JSON")` document.id central_time.0 central_time.1 Va_V.0 Va_V.1
#> <chr> <int> <chr> <chr> <dbl> <dbl>
#> 1 "{\"central_time\"~ 1 2020-04-06 15:4~ 2020-04-06 15:~ 286. 286.
Created on 2020-05-17 by the reprex package (v0.3.0)
system
Closed
June 7, 2020, 3:48am
3
This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.