Skip to content

sumerman/jsonfilter

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

jsonfilter (v0.1.0)

an otp approach to working with streaming json

jsonfilter is built via rebar, and continuous integration testing provided by travis-ci

current status: Build Status

jsonfilter is released under the terms of the MIT license

copyright 2014 alisdair sullivan

quickstart

to build library and run tests

$ rebar get-deps
$ rebar compile
$ rebar eunit

filtering a json stream

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">>].

About

an otp approach to working with streaming json

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Erlang 100.0%