PageRenderTime 46ms CodeModel.GetById 44ms app.highlight 0ms RepoModel.GetById 1ms app.codeStats 0ms

/lib/App/PipeFilter.pm

https://github.com/rcaputo/app-pipefilter
Perl | 97 lines | 2 code | 3 blank | 92 comment | 0 complexity | 08755e35d92be0e6d9b50f71ca0861f5 MD5 | raw file
 1package App::PipeFilter;
 2
 31;
 4
 5=pod
 6
 7=head1 NAME
 8
 9App::PipeFilter
10
11=head1 DESCRIPTION
12
13App::PipeFilter is a distribution of shell pipeline filters designed
14to work with structured data like JSON rather than whitespace
15separated fields.
16
17For example, jcut is a simple version of cut(1) that understands JSON
18objects rather than whitespace separated fields.
19
20  % head -1 sample.json
21  {"network":"freenode","channel":"#perl","nick":"dngor","karma":"120"}
22
23  % jcut -o network -o channel < eg/sample.json | sort | uniq
24  {"network":"efnet","channel":"#perl"}
25  {"network":"efnet","channel":"#poe"}
26  {"network":"efnet","channel":"#reflex"}
27  {"network":"freenode","channel":"#perl"}
28  {"network":"freenode","channel":"#poe"}
29  {"network":"freenode","channel":"#reflex"}
30  {"network":"magnet","channel":"#perl"}
31  {"network":"magnet","channel":"#poe"}
32  {"network":"magnet","channel":"#reflex"}
33
34The jsonpath filter supports more complex expressions using
35JSON::Path's variant of JSONPath.
36
37  curl -s 'http://api.duckduckgo.com/?q=poe&o=json' |
38  jsonpath -o '$..Topics.*.FirstURL' -o '$..Topics.*.Text' |
39  grep -i perl |
40  jmap -i col0 -o url -i col1 -o title |
41  json2yaml
42  --- 
43  title: Perl Object Environment, a library for event driven multitasking for the Perl programming language
44  url: http://duckduckgo.com/Perl_Object_Environment
45
46=head1 DESIGN GOAL
47
48App::PipeFilter utilities generally follow the UNIX convention of
49printing one record per line of text.  This maximizes compatibility
50with UNIX utilities like sort(1), uniq(1) and grep(1).
51
52=head1 PRO TIPS
53
54JSON isn't particularly concise, so put grep(1), jcut(1) and other
55filters that eliminate data as early as possible in pipelines.
56
57=head1 SEE ALSO
58
59L<jcat> - concatenate and print JSON files
60
61L<jcut> - cut out selected portions of each JSON object in a file
62
63L<jmap> - map input JSON fields to output JSON fields by renaming them
64
65L<json2yaml> - convert files of JSON objects into a stream of YAML objects
66
67L<jsonpath> - use JSON::Path to cut out selected portions of JSON objects
68
69L<jsort> - sort input files of JSON objects on key fields
70
71L<mysql2json> - convert mysql -B output to JSON object streams
72
73L<http://json.org/>
74
75L<http://search.cpan.org/perldoc?JSON::Path>
76
77L<http://goessner.net/articles/JsonPath/>
78
79=head1 BUGS
80
81L<https://rt.cpan.org/Public/Dist/Display.html?Name=App-PipeFilter>
82
83=head1 REPOSITORY
84
85L<https://github.com/rcaputo/app-pipefilter>
86
87=head1 COPYRIGHT and LICENSE
88
89App::PipeFilter
90is Copyright 2011 by Rocco Caputo.
91All rights are reserved.
92App::PipeFilter
93is released under the same terms as Perl itself.
94
95=cut
96
97# vim: ts=2 sw=2 expandtab