0

I have downloaded some data from a platform and would like to convert it into a tibble I can manipulate in R. I have tried doing this, but continue coming up with errors. The structure of my JSON file is as follows

List of 7
 $ TimeSeries     :'data.frame':    3 obs. of  7 variables:
  ..$ UniqueId          : chr [1:3] "0a87d824b33b45a594a29968549c0a07" "959696fb9f5f44d98cf463c96fb7225d" "ea45700060f84899928cfc7b49348795"
  ..$ Identifier        : chr [1:3] "O2 (Dis).ODO Conc@GRDA/Pensacola Dam REW" "O2 (Dis).ODO Conc@GRDA/Pensacola Dam LEW" "O2 (Dis).ODO Conc@GRDA/Pensacola Dam CEN"
  ..$ Parameter         : chr [1:3] "O2 (Dis)" "O2 (Dis)" "O2 (Dis)"
  ..$ Label             : chr [1:3] "ODO Conc" "ODO Conc" "ODO Conc"
  ..$ Unit              : chr [1:3] "mg/l" "mg/l" "mg/l"
  ..$ LocationIdentifier: chr [1:3] "GRDA/Pensacola Dam REW" "GRDA/Pensacola Dam LEW" "GRDA/Pensacola Dam CEN"
  ..$ InterpolationType : chr [1:3] "InstantaneousValues" "InstantaneousValues" "InstantaneousValues"
 $ TimeRange      :List of 2
  ..$ StartTime: chr "2021-01-01T00:00:00.0000000+00:00"
  ..$ EndTime  : chr "2022-01-01T00:00:00.0000001+00:00"
 $ NumPoints      : int 0
 $ Points         : list()
 $ ResponseVersion: int 1
 $ ResponseTime   : chr "2023-07-05T16:26:47.9875745+00:00"
 $ Summary        : chr "Produced by AQUARIUS Time-Series Software.\r\nThe accuracy and reliability of this data is not guaranteed.  Aqu"| __truncated__

I would like to come out with a df that has the Date, Timestamp, and Value associated with each of the three locations in one dataframe.

Something like this.

enter image description here

I've tried using 'purrr' and 'tidyjson', unnesting the json file, and EVERYTHING on stackoverflow, but continue to get either parsing errors or character string errors.

The code I have originally is this

source("timeseries_client.R")
timeseries$connect("https://owrbaqts.aquaticinformatics.net","myusername","mypassword")

json<- timeseries$getTimeSeriesData(c("O2 (Dis).ODO Conc@GRDA/Pensacola Dam REW",
                                      "O2 (Dis).ODO Conc@GRDA/Pensacola Dam LEW",
                                      "O2 (Dis).ODO Conc@GRDA/Pensacola Dam CEN"),
                                        queryFrom = "2021-01-01T00:00:00Z",
                                        queryTo = "2022-01-01T00:00:00Z")

str(json)
jsondf<-as.data.frame(json)
margusl
  • 7,804
  • 2
  • 16
  • 20
Andrea
  • 11
  • 2
  • What errors are you actually coming up with? What does your data actually look like? – stefan_aus_hannover Jul 05 '23 at 17:04
  • > jsondf<-as.data.frame(json) Error in (function (..., row.names = NULL, check.rows = FALSE, check.names = TRUE, : arguments imply differing number of rows: 3, 1, 0 Error in exists(cacheKey, where = .rs.CachedDataEnv, inherits = FALSE) : invalid first argument Error in if (maxRows != -1 && nrow(data) > maxRows) data <- head(data, : missing value where TRUE/FALSE needed – Andrea Jul 05 '23 at 17:14
  • You can't give `NULL` to `row.names`. It wants a `TRUE` or `FALSE` – stefan_aus_hannover Jul 05 '23 at 17:15
  • I'm pretty new to RStudio and have never worked with JSON files. What would you suggest to try? – Andrea Jul 05 '23 at 17:21
  • You're giving an argument a NULL that is wanting a TRUE or FALSE. Try changing the NULL to FALSE. You didn't share any code so I can only make assumptions. – stefan_aus_hannover Jul 05 '23 at 17:23
  • source("timeseries_client.R") timeseries$connect("https://owrb-aqts.aquaticinformatics.net","myusername","mypassword") json<- timeseries$getTimeSeriesData(c("O2 (Dis).ODO Conc@GRDA/Pensacola Dam REW", "O2 (Dis).ODO Conc@GRDA/Pensacola Dam LEW","O2 (Dis).ODO Conc@GRDA/Pensacola Dam CEN"), queryFrom = "2021-01-01T00:00:00Z", queryTo = "2022-01-01T00:00:00Z") – Andrea Jul 05 '23 at 17:26
  • and then the jsondf<- as.data.frame(json) – Andrea Jul 05 '23 at 17:28
  • Format your code above in your question. Its hard to read when placed in a comment – stefan_aus_hannover Jul 05 '23 at 17:32
  • Posted as an edit – Andrea Jul 05 '23 at 17:53
  • Please do not post pictures of code. Rather copy and paste the code directly. – Phil Jul 05 '23 at 18:02
  • code posted directly – Andrea Jul 05 '23 at 18:16
  • 1
    You already got an example JSON response (as you posted the structure). Why not just provide this sample in a reproducible way (using `dput`), your expected output (`dput` again) and edit the original question to result in a https://stackoverflow.com/help/minimal-reproducible-example ? At the same time you could check whether it's only the misspelled URL in your question that breaks the code. – I_O Jul 06 '23 at 05:09

0 Answers0