Parse R Character Vector into DataFrame

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:

# character
# 1 

# {"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}}'

#> # A tbl_json: 1 x 5 tibble with a "JSON" attribute
#>   `attr(., "JSON")` 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)

This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.