diff options
author | Adam Kocoloski <kocolosk@apache.org> | 2009-11-21 17:01:50 +0000 |
---|---|---|
committer | Adam Kocoloski <kocolosk@apache.org> | 2009-11-21 17:01:50 +0000 |
commit | 3a4fad07cb5097598eefd0cd7f588c5881a61c8f (patch) | |
tree | 6945d805eb72a37a5b27ae14a7ec2d1e8690fdac /src/couchdb/couch_util.erl | |
parent | a2ebd6155b8171befd8f55b42c48bc563bb330b0 (diff) |
upgrade mochiweb to r113, use hooks instead of forking mochijson2. COUCHDB-474
git-svn-id: https://svn.apache.org/repos/asf/couchdb/trunk@882941 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'src/couchdb/couch_util.erl')
-rw-r--r-- | src/couchdb/couch_util.erl | 14 |
1 files changed, 14 insertions, 0 deletions
diff --git a/src/couchdb/couch_util.erl b/src/couchdb/couch_util.erl index d02be8d9..da62375c 100644 --- a/src/couchdb/couch_util.erl +++ b/src/couchdb/couch_util.erl @@ -20,6 +20,7 @@ to_hex/1,parse_term/1, dict_find/3]). -export([file_read_size/1, get_nested_json_value/2, json_user_ctx/1]). -export([to_binary/1, to_integer/1, to_list/1, url_encode/1]). +-export([json_encode/1, json_decode/1]). -include("couch_db.hrl"). -include_lib("kernel/include/file.hrl"). @@ -406,3 +407,16 @@ url_encode([H|T]) -> end; url_encode([]) -> []. + +json_encode(V) -> + Handler = + fun({L}) when is_list(L) -> + {struct,L}; + (Bad) -> + exit({json_encode, {bad_term, Bad}}) + end, + (mochijson2:encoder([{handler, Handler}]))(V). + +json_decode(V) -> + try (mochijson2:decoder([{object_hook, fun({struct,L}) -> {L} end}]))(V) + catch _:_ -> throw({invalid_json,V}) end. |