Precommit Hook Difficulties

Greg Pascale greg at
Sat Sep 17 19:11:35 EDT 2011


I'm trying to write a simple precommit hook to modify a JSON object by
removing certain fields. The simplest way to do this, I figure, is to decode
the object's value with mochijson2, remove the fields I don't want,
re-encode it, and update the value.

What happens, though, is my object ends up somehow mangled. When I inspect
it via curl, it sort of looks like JSON, but characters like "{" and ":"
seem to be replaced with garbage.

For example, what should read "hostname":"" looks like *

To try to diagnose the issue, I reduced my hook to the simplest possible
case. I don't even modify the JSON, I just decode the object and re-encode
exactly the same value, but I still have the problem. The code is pasted

*precommit(RiakObject) ->*
*        Value = riak_object:get_value(RiakObject),*
*        {struct, TermList} = mochijson2:decode(Value),*
*        riak_object:apply_updates(*
*          riak_object:update_value(RiakObject, *
*                                   mochijson2:encode({struct, TermList}))).

Can anybody point out what I'm doing wrong?

Clipboard <> is hiring<>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <>

More information about the riak-users mailing list