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