# ImportString JSON possible bug

My problem is when I catch up some json output of whatever method and process it with ImportString[%, "JSON"], The first time when it executes, it works and then without doing anything, it stops working, and an error appears forever in the session. Then, I should restart Mathematica.

Import::fmterr: Cannot import data as JSON format. >>


For example, I could try with URLFetch, you could use other like ServiceExecute , I saw that other guys get the same errors.

URLFetch["https://api.twitter.com/1.1/application/rate_limit_status.\
json?resources=search",
"Method" -> "GET",
"Headers" -> { "Authorization" -> "Bearer " <> $token} ]  Out: "{\"rate_limit_context\":{\"application\":\"ZIfS6A0hLFFGn0rTK8AA\"},\"\ resources\":{\"search\":{\"\\/search\\/tweets\":{\"limit\":450,\"\ remaining\":441,\"reset\":1417461650}}}}"  Using ImportString[%, "JSON"] {"resources" -> {"search" -> {"/search/tweets" -> {"reset" -> 1417464421, "limit" -> 450, "remaining" -> 450}}}, "rate_limit_context" -> {"application" -> "ZIfS6A0hLFFGn0rTK8AA"}}  And in an unexpected way, if I try the same: Import::fmterr: Cannot import data as JSON format. >>  After that, all functions that can process JSON stop working. Any idea? UPDATE: If you can reproduce my current problem in a real example. I'm doing the next: $token = "AAAAAAAAAAAAAAAAAAAAACIzUwAAAAAAIcK0ag%2BYQgJMWChjJFIOvC3oBc0%3DPSlfWyj98uQTquGq9oBuVwVovUCfKuOwHSpSSIvMZSJeBRsbQD";


The next function use ImportString and sometimes it fails.

Clear[buscarTuits];
buscarTuits[expr_Association:{}] := Module[
{query, res},
res = ImportString[URLFetch[query,
"Method"-> "GET",
"Headers"-> { "Authorization"-> "Bearer "<>\$token}], "JSON"];
Return[res];
];

buscarTuits[expr_String]:= buscarTuits[Association["q"-> expr]];


And,

buscarTuits["wolfram"]


Sometimes appear the next error and others times don't.

Import::fmterr: Cannot import data as JSON format. >>


This Bug after all discussion here. It was notified to Wolfram Support [CASE:1884981]. I'll update this post in the future with the responses by support assistance .

• Version Mathematica 10 – jonaprieto Dec 1 '14 at 22:01
• This time, it works for me, :( {"search_metadata" -> {"since_id" -> 0, "count" -> 15, "max_id_str" -> "539548678797922304", "refresh_url" -> "?since_id=539548678797922304&q= nixpxon&include_entities=1", "completed_in" -> 0.018, "max_ id" -> 539548678797922304, "query " -> "nixpxon", "since_id_ str" -> "0"}, "statuses" -> {}} – jonaprieto Dec 1 '14 at 22:57
• You are right. On a fresh kernel it works for me too. But this illustrates nicely the phenomenon that you described, i.e. that once it failed everything JSON keeps failing – Sjoerd C. de Vries Dec 1 '14 at 23:08
• It looks like the size of the JSON string may be a factor. I found that sizes of 7KB and below import fine but ones above 35KB yield the error. – Sjoerd C. de Vries Dec 1 '14 at 23:19
• @jonaprieto Did you even get an update from Wolfram Support on the bug report you filed? Is this still relevant to later versions of MMA? – MarcoB May 29 '18 at 19:02