Actually it looks like I can remove the JSON decode/encode and I still see
the same issue. Just reading and writing the value is enough, so all I'm
doing now is

*precommit(RiakObject) ->*
*        Value = riak_object:get_value(RiakObject),*
*        riak_object:apply_updates(*
*          riak_object:update_value(RiakObject, Value)).*

I'm really baffled here. The only documentation I know of for this code is
at
http://basho.github.com/riak-erlang-client/riak-erlang-client/riakc_obj.html
and
it really doesn't say much.

-Greg
Clipboard

On Sat, Sep 17, 2011 at 4:11 PM, Greg Pascale <g...@clipboard.com> wrote:

> Hi,
>
> 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":"www.google.com" looks like *
> hostnamea"ja:la"mwww.google.coma"j*
>
> 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
> below
>
> *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?
>
> --
> Greg
> Clipboard <http://www.clipboard.com> is hiring<http://www.clipboard.com/jobs>
> !
>
>


-- 
Greg
Clipboard <http://www.clipboard.com> is hiring<http://www.clipboard.com/jobs>
!
_______________________________________________
riak-users mailing list
riak-users@lists.basho.com
http://lists.basho.com/mailman/listinfo/riak-users_lists.basho.com

Reply via email to