You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I don't think there is nothing specific to this library regarding that. You either have the option of using cjson.safe (that is documented), or just protecting the call with pcall:
+ $ lua5.4
Lua 5.4.3 Copyright (C) 1994-2021 Lua.org, PUC-Rio
+> cjson = require 'cjson'
+> cjson_safe = require 'cjson.safe'
+> pcall(cjson.decode, "foo")
false Expected value but found invalid token at character 1
+> cjson_safe.decode("foo")
nil Expected value but found invalid token at character 1
Hi,
Since this is not addressed in documentation I thought I would ask here - what's the "right" way of handling invalid JSONs without blowing up?
The text was updated successfully, but these errors were encountered: