Skip to content

Instantly share code, notes, and snippets.

@sinkovsky
Created October 12, 2009 11:11
Show Gist options
  • Save sinkovsky/208332 to your computer and use it in GitHub Desktop.
Save sinkovsky/208332 to your computer and use it in GitHub Desktop.
tick_to_json_object(Rec) when is_record(Rec, tick) ->
Keys = [ <<"timestamp">>, <<"value">> ],
{_Series_id, Timestamp} = Rec#tick.id,
Value = Rec#tick.value,
{struct, lists:zip(Keys, [Timestamp, Value])};
tick_to_json(Tick) ->
Encode = mochijson2:encoder([{utf8, true}]),
try
List = case Tick of
R when is_record(R, tick) ->
[ tick_to_json_object(R) ];
L when is_list(List) ->
[ tick_to_json_object(R) || R <- List ]
end,
list_to_binary( Encode( tick_to_json_object(Tick) ) )
catch
error:_ ->
error
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment