an otp approach to working with streaming json
jsonfilter is built via rebar, and continuous integration testing provided by travis-ci
jsonfilter is released under the terms of the MIT license
copyright 2014 alisdair sullivan
$ rebar get-deps
$ rebar compile
$ rebar eunit
filter a json stream
// JSON
{ "books": [
{ "title": "a wrinkle in time",
"author": "madeleine l'engel",
"editions": [1962, 1978, 2007]
},
{ "title": "all creatures great and small",
"author": "james herriot",
"editions": [1972, 1992, 2004, 2014]
}
]}
%% a callback module
-module(authors).
-export([init/1, handle_value/3, finish/1]).
%% init's arg is the third argument passed to `filter/3`
init([]) -> [].
handle_value([<<"books">>, _, <<"author">>], Author, State) ->
[Author] ++ State;
%% if you don't handle all paths filtering will fail with a `function_clause`
%% error
handle_value(_, _, State) -> State.
finish(State) -> lists:reverse(State).
1> jsonfilter:filter(JSON, authors, []).
[<<"james herriot">>, <<"madeleine l'engel">>].