Raynor
Raynor

Reputation: 277

JSON parsing error, invalid character

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?

Upvotes: 6

Views: 7665

Answers (2)

Amrita
Amrita

Reputation: 11

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

Upvotes: 1

Raynor
Raynor

Reputation: 277

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.

Upvotes: 2

Related Questions