Created
October 12, 2009 11:11
-
-
Save sinkovsky/208332 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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