JSON parsing error, invalid character - json

I am using fromJSON from the jsonlite package in [R] to call GetPlayerSummaries from the Steam API (https://developer.valvesoftware.com/wiki/Steam_Web_API) to get access to a user's data. For most calls it's working fine, but at some point I get an error:
Error in feed_push_parser(readBin(con, raw(), n), reset = TRUE) :
lexical error: invalid bytes in UTF8 string.
publicâ„¢ II: The Sith Lordsâ", "gameid": "208580" },
(right here) ------^
When I access the call in my browser I find a � on the spot where it is probably giving the error. I could Try-Catch but I'd really like to get this data. How to get around this?

For my purpose, reading with readLines and then parsing it seemed to work
readlines <- readLines(link, warn = FALSE)
parse <- fromJSON(readlines)
I have no idea why and how this works, and may hence be not the most clean solution, but it seems to be robust for my purposes.

You have to use use jsonlite's streaming function
json_file <- stream_in(file("abc.json"))
It has been answered in Stack Overflow here:
Error parsing JSON file with the jsonlite package
and here:
Export JSON from Spark and input into R

Related

ijson fails with trailing garbage parse error

for prefix, event, value in parser:
print(prefix)
I get the following error after executing the above code , I dont understand what the error is.
ijson.common.IncompleteJSONError: parse error: trailing garbage
nt":19485,"verified":false}} {"user_id":1408970940,"id":4496
(right here) ------^
Seems you are trying to parse a JSON document with more than one top-level object, which is not standard. ijson allows for this though if you give the multiple_values=True flag to the method you are using.

Getting error while converting json file to a data frame using jsonlite

I am using the tweetscores package of R to get 'tweets list from twitter. The tweets are stored in json format. While converting it to a data frame I get a lexical error
' Error: lexical error: inside a string, '\' occurs before a character which it may not.".
Any solution to the mentioned error.
A part of the json file text
":[{"text":["MUFC"],"indices":[[83],[88]]}],"symbols":[],"user_mentions":[],"urls":[]},"metadata":{"iso_language_code":["en"],"result_type":["recent"]},"source":["http://twitter.com/download/iphone\" rel=\"nofollow\">Twitter for iPhone</a>"],"in_reply_to_status_id":null,"in_reply_to_status_id_str":null,"in_reply_to_user_id":null,"in_reply_to_user_id_str":null,"in_reply_to_screen_name":null,"user":{"id":[7.32108114527322e+017],"id_str":["732108114527322112"],"name":["wwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwww(^o^)/"],"screen_name":["SukiSukinal"],"location":["+6222"],"description":["Alliansi osaosi ngevote kagak. katanya sih fans a.k.a + "],"url":null,"entities":{"description":{"urls":[]}},"protected":[false],"followers_count":[163],"friends_count":[107],"listed_count":[4],"created_at":["Mon May 16 07:19:11 +0000
Json format does not allow backslashes so you need to escape them. replace any '\' character found with '\\'. Refer [here][1]
[1]: http://www.json.org/ for more info
You likely have an incomplete json string, which may be caused by the package or by an interrupted connection to Twitter's API. A complete json string returned from Twitter should look something like the following:
which I got using rtweet's stream_tweets() function. With a complete string returned by Twitter's REST or stream API, you should be able to convert the data using basically any json parser (e.g., jsonlite::fromJSON()).

Problems importing JSON data with R

I'm using the jsonlite library to try to get some JSON data and turn it into a data frame that I could use, but so far it hasn't worked. I've tried three methods so far:
testData = fromJSON("<json file location>")
Which outputs:
Error in feed_push_parser(readBin(con, raw(), n), reset = TRUE) :
parse error: trailing garbage
n_reply_to_status_id":null} {"contributors":null,"text":"Te
(right here) ------^
So I figured that if the quotes caused error, I'd just have to remove them:
singleString <- paste(readLines("<json file location>"), collapse=" ")
singleString = gsub('"', "",singleString)
singleString = fromJSON(singleString)
Which outputs:
Error: lexical error: invalid char in json text.
{contributors:null,text:A colour
(right here) ------^
It seems to be pointing to an 'o' in the text. If I delete that 'o' it just points to the 'n' that comes after it.
My last attempt I read on a forum post of someone having a similar problem that it should solve it:
stream = stream_in(file("<json file location>"))
I was pretty happy to see that this did not return an error and that a data frame named "stream" had been added to memory, but when I tried to view that data frame...
> View(stream)
Error in View : 'names' attribute [1] must be the same length as the vector [0]
I'm not exactly sure what this means or what I could do about it in this situation.
If you have an idea of I could get this data loaded correctly, I would deeply appreciate it. Thanks!
EDIT: Here is the JSON data in question: https://gist.github.com/geocachecs/f68d769aeed8e019a26cc230559bbf7f

R - JSON Returned from RCurl::getURL has Special Characters that make it invalid with fromJSON

How can make sure that the result of my getURL() call is properly formatted to be parsed using from JSON?
Details
If I take the string for api URL and paste that into Chrome, then copy and paste out the resulting JSON, RJSONIO::fromJSON() will parse it. However, if I pass the variable test, as in my code below, to fromJSON(), I get this error:
Error in fromJSON(content, handler, default.size, depth, allowComments, :
invalid JSON input
In going through the differences between the two, I found some issues encoding escaped character sequences such as "\\\"\\\\\\\"" which I am able to search for and replace. However there are some other things, where for example, the broken JSON will show " " while the working JSON will show "\u00A0".
library(RJSONIO)
library(RCurl)
apiURL= #sorry I can't post the actual URL due to company security policies
test<-getURL(apiURL,userpwd="myusername:mypassword",httpauth=1L)
transcripts1 <- fromJSON(test)

How to typecast System.String to BOO.lang.hash in Unityscript Unity3D?

I found a tutorial for server implementation in a game on this link:
http://unity-tutorials.blogspot.in/
I implemented the code for my server sending in the following data on the Login Section to my Server:
{"email":"rudi#mrpatch.co", "pass": "mrpatch"}
This server is implementing JSON and is giving the below response :
Receive response: "{\"status\":\"success\",\"data\":[{\"id\":\"1\",\"email\":\"rudi#mrpatch.co\",\"password\":\"mrpatch\",\"first_name\":\"Rudi\",\"last_name\":\"Ullon\",\"birth_date\":\"1981-03-20\",\"status\":\"1\"}]}"
There is a JSON parser script in this project, which returns System.string , this is being used by a parser in my other script LoginService.js
But while I am trying to store this in a Boo.Lang.Hash (hashtable) it gives me error in following code:
var parsed : Boo.Lang.Hash = JSONParse.JSONParse(httpResponse.text);
This is the Error message I am getting:
InvalidCastException: Cannot cast from source type to destination type.
LoginService+$sendLoginData$6+$.MoveNext () (at Assets/Scripts/StartMenu/LoginService.js:61)
I have tried saving it a Boo.Lang.Hash, as String etc. but nothing seems to be working.
if you have json you can do in this way.
var parsed : Boo.Lang.Hash = JSONParse.JSONParse(your json );
Oh boy...
You seem to have quite some conceptual issues with type casting and that's a far too broad topic (joke link). :P
The error message means you can't convert from String to that Hashtable through casting. You need a function to convert it for you or do it yourself.
The JSONParse you mentioned can actually do it:
var jsonData : json = json.fromString(httpResponse.text);
At least now you have jsonData.values which can be easily converted to a Hashtable...
But keep in mind "Hashtables" are obsolete and even the Unity Player will warn you about it. Read more.
you must use the JsonPare.js from source code on the demo.https://docs.google.com/file/d/0B0HipNssJJD-bEh0Wi1XeV9PSlE/edit