5

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?

Raynor
  • 267
  • 3
  • 10
  • Could you copypaste some example data on pastebin or so? – Jeroen Ooms Oct 18 '15 at 17:56
  • I suspect this is the part that is acting up, at one of the bottom lines http://pastebin.com/DesK5dyr – Raynor Oct 18 '15 at 18:16
  • Actually your example json only fails because there is a trailing comma at the end that should not be there. – Jeroen Ooms Oct 18 '15 at 21:26
  • You are probably right, I changed the question to include the full error as given by [R]. So it's not the unknown character that's acting up, but the comma, if so, I'm not sure how to solve this with some code. I'm also not sure why it gives the error, some other lines (e.g., 'timecreated') also end with a comma. – Raynor Oct 19 '15 at 03:21
  • Possible duplicate of [Error parsing JSON file with the jsonlite package](http://stackoverflow.com/questions/26519455/error-parsing-json-file-with-the-jsonlite-package) – miken32 Aug 22 '16 at 22:42

2 Answers2

2

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.

Raynor
  • 267
  • 3
  • 10
1

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

Community
  • 1
  • 1
Amrita
  • 11
  • 2