Skip to content
This repository has been archived by the owner on Jan 12, 2023. It is now read-only.

Commit

Permalink
Merge pull request #13 from hcs42/json_terms
Browse files Browse the repository at this point in the history
Add functions that return a JSON term (not a JSON string)
  • Loading branch information
jonasrichard committed Jan 7, 2015
2 parents 46f5d44 + 9b94401 commit 8be51d7
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions src/ejson.erl
Original file line number Diff line number Diff line change
@@ -4,6 +4,8 @@
to_json/2,
to_json_module/2,
to_json_modules/2,
to_json_term/2,
to_json_term_module/2,
json_props/1
]).

@@ -26,6 +28,13 @@ to_json_module(Term, Module) ->
%% Call to_json with the Options we got
to_json(Term, Opts).

to_json_term_module(Term, Module) ->
%% Get -json attributes from module info
Opts = json_props([Module]),

%% Call to_json with the Options we got
to_json_term(Term, Opts).

json_props(ModuleList) ->
lists:foldl(
fun(Module, Acc) ->
@@ -68,6 +77,9 @@ to_json(Term, Options) ->
Enc = conv(Term, Options),
jsx:encode(Enc).

to_json_term(Term, Options) ->
conv(Term, Options).

conv(Tuple, Options) when is_tuple(Tuple) ->
%% Get record name and values from the tuple
[RecName | Vals] = erlang:tuple_to_list(Tuple),

0 comments on commit 8be51d7

Please sign in to comment.