I had a quick play with this. Mochijson2:encode returns an erlang I/O list. You can convert back to a proper binary with iolist_to_binary().
precommit_json_identity(Obj) -> Values = riak_object:get_values(Obj), {struct, TermList} = mochijson2:decode(hd(Values)), riak_object:apply_updates( riak_object:update_value(Obj, iolist_to_binary(mochijson2:encode({struct, TermList})))). Cheers, Jon On Mon, Sep 19, 2011 at 1:50 PM, David Smith <diz...@basho.com> wrote: > On Sat, Sep 17, 2011 at 5: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 > > If I had to guess, I would say that you are seeing some sort of weird > unicode encoding of the double-quote character; maybe the data stored > was UTF-16 encoded? I.e. is there some unicode character that would > display a " but actually be stored as [a, "]? > > D. > > -- > Dave Smith > Director, Engineering > Basho Technologies, Inc. > diz...@basho.com > > _______________________________________________ > riak-users mailing list > riak-users@lists.basho.com > http://lists.basho.com/mailman/listinfo/riak-users_lists.basho.com >
_______________________________________________ riak-users mailing list riak-users@lists.basho.com http://lists.basho.com/mailman/listinfo/riak-users_lists.basho.com