PageRenderTime 48ms CodeModel.GetById 41ms app.highlight 0ms RepoModel.GetById 1ms app.codeStats 0ms

/lib/App/PipeFilter.pm

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