jeroen / jsonlite

A Robust, High Performance JSON Parser and Generator for R
http://arxiv.org/abs/1403.2805
Other
380 stars 40 forks source link

My streaming json string throws an error in my jasonlite fromJSON R script function #199

Open maximuslee1226 opened 7 years ago

maximuslee1226 commented 7 years ago

I have a streaming json from a simulator coming in and fail in R script within AzureML Execute R script.

I get the following error

"An exception was encountered while invoking the Azure ML function TelcoMLFunction with endpoint URL HTTP error code: BadRequest. Reason phrase: Bad Request\r\nResponse Headers:\r\nx-ms-request-id: 7fc44229-bfa0-41a0-9692-91849b67d10a\r\nDate: Tue, 05 Sep 2017 04:45:14 GMT\r\nETag: \"1ba412a1-68e5-4561-8290-d6ae955900f6\"\r\nServer: Microsoft-HTTPAPI/2.0\r\nResponse Body:\r\n{\"error\":{\"code\":\"LibraryExecutionError\",\"message\":\"Module execution encountered an internal library error.\",\"details\": {\"code\":\"FailedToEvaluateRScript\",\"target\":\"Execute R Script Piped > RPackage)\",\"message\":\"The following error occurred during evaluation of R script: R_tryEval: return error: Error: lexical error: invalid char in json text.\n NA\n (right here) ------^\n\"}]}}\r\nSee Azure Machine Learning REST API Error Codes for more details: https://msdn.microsoft.com/en-us/library/azure/dn913081.aspx\r\n\r\n",` I've been searching google for every possible post with jsonlite failures and the following error code and I can't get it to work. The tricky part of it is that if I feedin json strings in tsv file format, my script works, but as soon as the streaming json data comes into the R script module, it fails with the above error.

my json format is

{"RecordType":"MO","SystemIdentity":"d0","FileNum":"0","SwitchNum":"UK","CallingNum":"012392572","CallingIMSI":"466922202613463","CalledNum":"567881498","CalledIMSI":"466923100807296","DateS":"20170814","TimeS":null,"TimeType":3,"CallPeriod":0,"CallingCellID":null,"CalledCellID":null,"ServiceType":"b","Transfer":1,"IncomingTrunk":null,"OutgoingTrunk":"409","MSRN":"886932428687","CalledNum2":null,"FCIFlag":null,"callrecTime":"2017-08-14T23:57:16.0000000Z","EventProcessedUtcTime":"2017-08-14T23:57:16.2330567Z","PartitionId":1,"EventEnqueuedUtcTime":"2017-08-14T23:57:17.7740000Z"} My code is written like this

df <- maml.mapInputPort(1) # class: data.frame df <- df[[1]] df <- gsub('""', '"', df) df <- lapply(df, fromJSON) df <- lapply(df, function(x) { x[sapply(x, is.null)] <- "NA" unlist(x) }) df <- as.data.frame(matrix(unlist(df), nrow=length(df), ncol=25, byrow=T),stringsAsFactors=FALSE) I've tried so many different permutations of json parsing for months, but I still can't get it work.

Please help Jeroen, Thank you! Brandon

hannarud commented 7 years ago

Could you reproduce this error on your local machine?