Reputation: 918
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
Upvotes: 1
Views: 2518
Reputation: 41393
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).
Upvotes: 1