Please help with SyntaxError: JSON.parse in storage integration


I’m trying to access the stored data from my GPS LW-001BG tracker Moko via storage integration.
SyntaxError error occurs: JSON.parse: unexpected non-whitespace character after JSON data at line 2 column 1 of the JSON data
In the V2 version, I was able to access the stored data via Swagger without any problems.
Please advise what to do with this error.


Hi @Petr,

The main issue here is that the response type is not application/json but text/event-stream, which is a stream of JSON formatted messages (separated by empty lines). Here is an example response (quoted from the docs):



Attempting to parse this as a JSON object will raise the error message that you encounter.

Note that the default response message contains a lot of fields for the uplink message. You can limit the fields that are returned by specifying field mask paths in the request, e.g.:

curl -G "" \
    -H "Authorization: Bearer $API_KEY" \
    -H "Accept: text/event-stream" \
    -d "limit=10" \
    -d "field_mask=up.uplink_message.f_cnt,up.uplink_message.frm_payload,up.uplink_message.decoded_payload"

See also the documentation for more info on how to use the HTTP API to retrieve uplink messages persisted in the Storage Integration. Hope this helps!

@neoaggelos, to actually answer the question for @Petr:

Once you get the response, in Javascript you need:

response = '{"data": [' + response.replace(/\n\n/gm, ',').slice(0, -1) + ']}';

If you do Python for an application or service it is:

theJSON = "{\"data\": [" + r.text.replace("\n\n", ",")[:-1] + "]}";

The docs are good if you are really old (like me) & can see “The Matrix”. I get the whole Event Stream idea but as it does not have any CORS options in the browser it’s a b1tch to use and the gaps between results are catching people out with other code.

Thank you for your answers.
To be honest, I’m just an ordinary user who started researching LoRaWAN networks as a hobby. I could think of some uses for LoRaWAN devices that I could test in practice, and the TTS (TTN) network seems to me to be the best choice. Now I’m thinking of placing a gateway on the house.
Unfortunately, I don’t understand programming, so I don’t know what your advice means to me. Apparently there’s some wrong format.
Previously, I could easily view the history of data sent by my tracker on Swagger. It was useful for testing. Now it is not possible in the TTS network.
Would it be possible, please, to explain to me in a simple way how to get history back?
Otherwise, I successfully use the TagoIO application to display the location of the tracker on the map, but I would still like to see a functional storage integration.

Yes it is. But you have to set the limit to 1 as the issue is to do with the way the JSON is sent. If you set the sort to received data in reverse, you’ll get the latest one:

Not really, not without you learning a bit of code. If a supermodel can do it, or a US Senator who goes on to be the President can do it, I’m sure you can too.

On the plus side, I am working on such tools - I have already done it for Data Storage but it needs some tidy up and I’m waiting on an official answer to the short name of the new v3 stack - if anyone cares to prompt TTI on this, that would be super useful: How do we refer to the v3 Stack in third party offerings · Issue #4130 · TheThingsNetwork/lorawan-stack · GitHub