Skip to content

Instantly share code, notes, and snippets.

@roidrage
Created June 17, 2011 12:18
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save roidrage/1031311 to your computer and use it in GitHub Desktop.
Save roidrage/1031311 to your computer and use it in GitHub Desktop.
-module(validate_json).
-export([validate/1]).
validate(Object) ->
try
mochijson2:decode(riak_object:get_value(Object)),
Object
catch
throw:invalid_utf8 ->
{fail, "Invalid JSON: Invalid UTF-8 character"};
error:Error ->
{fail, "Invalid JSON: " ++ binary_to_list(list_to_binary(io_lib:format("~p", [Error]))).}
end.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment