Hello R programmers
I have been using the following implementation of plumber locally:
startWebListener <- function(modelName, httpPort) {
cust_json <- function() {
function(val, req, res, errorHandler) {
tryCatch({
json <- jsonlite::toJSON(
val,
auto_unbox = TRUE,
pretty = FALSE,
digits = 15
)
print(json)
json <- gsub("\"NaN\"", "null", json)
json <- gsub("\"N/A\"", "null", json)
res$setHeader("Content-Type", "application/json")
res$body <- json
return(res$toResponse())
}, error = function(e) {
errorHandler(req, res, e)
})
}
}
register_serializer("cust_json", cust_json)
r <- plumb(modelName)
r$run(host = "0.0.0.0", port = httpPort)
}
Recently I updated plumber, jsonlite and httr libraries to their latest version. After this, I have been getting the following error response every time I use the API:
<simpleError: lexical error: invalid char in json text.
incomingJSON={ "Id": "fa67
(right here) ------^
Not sure where the issue comes from. My data has not changed and there are no special characters. The application and the R code are running locally under the same network.
Any idea?
Thanks