I have incoming data, which I store in a variable messages:
connection = ContextIO::Connection.new(key, secret)
messages = connection.all_messag
[] and {}, respectively.messages. It is probably empty, unset or consists of a single digit (like 4), which is not valid JSON, but accepted by many JSON implementations.While I totally agree with the other answer, in my case I had a valid JSON string but was still receiving the "JSON text must contain at least two octets" error message when trying to JSON.parse.
My issue was that I was not specifying content type of application/json. Once I added that, JSON.parse worked without error.
Hope this helps someone else.