Skip to content

Instantly share code, notes, and snippets.

@sinkovsky
Created October 10, 2009 12:13
Show Gist options
  • Save sinkovsky/206809 to your computer and use it in GitHub Desktop.
Save sinkovsky/206809 to your computer and use it in GitHub Desktop.
tick_list_from_json(Series_id, Json) ->
try mochijson2:decode(Json) of
List when is_list(List) ->
[ json_struct_to_tick(Series_Id, P) || P <- List ];
Struct when is_tuple(Struct) ->
[ json_struct_to_tick(Series_Id, Struct) ]
catch
_Any ->
{error, bad_json}
end.
json_struct_to_tick(Series_id, {struct, Struct}) ->
#tick{
id = {Series_id, proplists:get_value(<<"timestamp">>, Struct)},
value = proplists:get_value(<<"value">>, Struct)
}.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment