ajschumacher / rjstat

read and write JSON-stat with R
Other
31 stars 6 forks source link

Feature request: support for R list objects #23

Closed MarkPaulin closed 1 month ago

MarkPaulin commented 1 month ago

This package is great, I really appreciate the work that's gone into it and I would love to use it in my own work.

The API I'm working with is a bit odd in that it returns a JSON-stat object nested inside a larger JSON response. At the moment, I need to do something like this:

req <- httr2::request(some_url)
resp <- httr2::req_perform(req)
resp_body <- httr2::resp_body_json(resp)
jsonstat_list <- resp_body [["result"]]
jsonstat_text <- jsonlite::toJSON(jsonstat_list)
resp_data <- rjstat::fromJSONstat(jsonstat_text)

Would it make sense to skip the JSON to list conversion when a list is passed into fromJSONstat()? Or expose parse_list() or similar functionality?

Happy to submit a PR if you think this would be useful, but I appreciate it's a bit of a niche use-case.

ajschumacher commented 1 month ago

Hi! I hardly know, as I don't have this use case, but if you have an idea for a PR, I think it would be welcome! 👍

MarkPaulin commented 1 month ago

I've toyed around with this a little and I've had difficulties with the list I get from parsing the full response not matching the format expected by parse_list(). I think the solution would be to change how I handle the response object rather than parsing the entire thing.

I'm going to close this, thanks!

ajschumacher commented 1 month ago

Thanks for the update!