So I have a function that its sole purpose is to parse JSON's that get dynamically generated but not by my program. Sometimes those JSON's might not meet the proper syntax for a variety of reasons raging from network lag to simply broken json structures. To parse a JSON I use
try { JSON.parse(LARGE_JSON) } catch(e) { .. log the error }
For some reason now, after many parses it seems like my nodejs is leaking and finally encoutering an syntax error
SyntaxError: Unexpected token X in JSON at position 19837
at JSON.parse (<anonymous>)
at Pipe.channel.onread (internal/child_process.js:470:28)
That error crashes the whole process with it, even though I am using try catch. So I really don't understand how to tackle neither the memory leak nor the crashing process, what might the issue be?
Related
I'm getting the previous error while trying to load a simple JSON file:
{
"$schema": "http://json-schema.org/draft-04/schema#"
}
What I'm doing is trying to use act with this git action. However, even when trying to load the JSON with a dummy project it still gives me that error.
As you can see, the JSON is clearly valid, I'm not sure why it complains about that weird char in the beginning of the JSON. I double checked with this JSON validator and it says it's valid.
This was under Windows.
Windows introduced some weird chars in the beginning while outputting:
generate-schema -j .\config.json > .\config.schema.json.
I reran the command on a Linux machine.
In my React Native app, I have two different instances where I make an API call and then pass the response to the json() method. In the first instance, the promise resolves; in the second, it throws the following error "SyntaxError: Unexpected token v in JSON at position 0 at parse () at tryCallOne".
The response objects that I pass to json() are as follows:
First instance (successful)
Second instance (unsuccessful)
As far as I can tell, the only difference between these two is x-sourcefiles, but since they're both strings, I can't imagine that this would cause an error in the json() method.
When I've read other people's solutions, normally the problem was that the Response objects they passed to json() was not actually JSON (sometimes it was HTML etc). That obviously doesn't apply here since both objects, one of which is successful, are of the same type.
Does anyone have any insight or know how I could approach this?
I've got a rsyslog server sending logs to logstash (6.8). For the (very) vast majority of logs that I receive (windows, unix, etc) everything parses just fine.
input {
codec => json {
charset => "ISO-8859-1"
}
}
}
However when I receive some logs (I stress some) for event ID 4688 that contain binary at the end of the log event like the below example - I receive the error:
Json ParserError: Unexpected end-of-input within/between Object
entries
-NoProfile -NonInteractive -EncodedCommand KABOAGUAdwAtAEkAdABlAG0AIAAtAFQAeQBwAGUAIABEAGkAcgBlAGMAdABvAHIAeQAgAC0AUABhAHQAaAAgACQAZQBuAHYAOgB0AGUAbQBwACAALQBOAGEAbQBlACAAIgBhAG4AcwBpAGIAbABlAC0AdABtAHAALQAxADQAMwAzADAAOAA3ADYANQA5AC4AMgA4AC0ANwA0ADQANAA1ADMANgA1ADQAMQA2ADgANwAyACIAKQAuAEYAdQBsAGwATgBhAG0AZQAgAHwAIABXAHIAaQB0AGUALQBIAG8AcwB0ACAALQBTAGUAcABhAHIAYQB0AG8AcgAgACcAJwA7AA==
I'm at a loss at how to parse it. I don't really care about the binary, is there a way for me to chop off a log event after it see's -EncodedCommand before it gets run through a filter? All other 4688 events parse without any issue and a grok filter (if it makes it past the json parse) passes without issue either.
I have a REST POST API that receives json data and validates parameters. In the production environment, the API sometimes raises an exception:
JSON::ParserError : 822: unexpected token at ...
The stack trace is like:
> .../gems/ruby-2.2.10/gems/json-1.8.6/lib/json/common.rb:155:in `parse'
> .../gems/ruby-2.2.10/gems/json-1.8.6/lib/json/common.rb:155:in `parse'
> .../gems/ruby-2.2.10/gems/activesupport-4.2.10/lib/active_support/json/decoding.rb:26:in `decode'
It seems that the error occurs randomly; I cannot find any pattern.
When I try the same code with the dumped data, there is no parsing error.
I thought the error is due to running in concurrent, but I tried it in local with 1000 concurrent requests, which are far more than in the production environment, and it still works without any error.
I appreciate to throw some light.
What does the 822 mean in the error message? It does not seem to be the character position in the json data.
How can one check to see if a string is properly formatted in json? I am running into situations where I receive a partial json string, and then when trying to decode the erroneous string with Lua's json.decode, my application crashes.
Thanks
Note that there is a difference between crash and crash in Lua.
If you see segfaults, throw away your JSON library and use something else (there are plenty).
If you see a Lua error, just wrap JSON processing code in pcall or xpcall. (But, better, again, throw away your library, and pick a better one).