.\" Automatically generated by Pod::Man 4.14 (Pod::Simple 3.43) .\" .\" Standard preamble: .\" ======================================================================== .de Sp \" Vertical space (when we can't use .PP) .if t .sp .5v .if n .sp .. .de Vb \" Begin verbatim text .ft CW .nf .ne \\$1 .. .de Ve \" End verbatim text .ft R .fi .. .\" Set up some character translations and predefined strings. \*(-- will .\" give an unbreakable dash, \*(PI will give pi, \*(L" will give a left .\" double quote, and \*(R" will give a right double quote. \*(C+ will .\" give a nicer C++. Capital omega is used to do unbreakable dashes and .\" therefore won't be available. \*(C` and \*(C' expand to `' in nroff, .\" nothing in troff, for use with C<>. .tr \(*W- .ds C+ C\v'-.1v'\h'-1p'\s-2+\h'-1p'+\s0\v'.1v'\h'-1p' .ie n \{\ . ds -- \(*W- . ds PI pi . if (\n(.H=4u)&(1m=24u) .ds -- \(*W\h'-12u'\(*W\h'-12u'-\" diablo 10 pitch . if (\n(.H=4u)&(1m=20u) .ds -- \(*W\h'-12u'\(*W\h'-8u'-\" diablo 12 pitch . ds L" "" . ds R" "" . ds C` "" . ds C' "" 'br\} .el\{\ . ds -- \|\(em\| . ds PI \(*p . ds L" `` . ds R" '' . ds C` . ds C' 'br\} .\" .\" Escape single quotes in literal strings from groff's Unicode transform. .ie \n(.g .ds Aq \(aq .el .ds Aq ' .\" .\" If the F register is >0, we'll generate index entries on stderr for .\" titles (.TH), headers (.SH), subsections (.SS), items (.Ip), and index .\" entries marked with X<> in POD. Of course, you'll have to process the .\" output yourself in some meaningful fashion. .\" .\" Avoid warning from groff about undefined register 'F'. .de IX .. .nr rF 0 .if \n(.g .if rF .nr rF 1 .if (\n(rF:(\n(.g==0)) \{\ . if \nF \{\ . de IX . tm Index:\\$1\t\\n%\t"\\$2" .. . if !\nF==2 \{\ . nr % 0 . nr F 2 . \} . \} .\} .rr rF .\" .\" Accent mark definitions (@(#)ms.acc 1.5 88/02/08 SMI; from UCB 4.2). .\" Fear. Run. Save yourself. No user-serviceable parts. . \" fudge factors for nroff and troff .if n \{\ . ds #H 0 . ds #V .8m . ds #F .3m . ds #[ \f1 . ds #] \fP .\} .if t \{\ . ds #H ((1u-(\\\\n(.fu%2u))*.13m) . ds #V .6m . ds #F 0 . ds #[ \& . ds #] \& .\} . \" simple accents for nroff and troff .if n \{\ . ds ' \& . ds ` \& . ds ^ \& . ds , \& . ds ~ ~ . ds / .\} .if t \{\ . ds ' \\k:\h'-(\\n(.wu*8/10-\*(#H)'\'\h"|\\n:u" . ds ` \\k:\h'-(\\n(.wu*8/10-\*(#H)'\`\h'|\\n:u' . ds ^ \\k:\h'-(\\n(.wu*10/11-\*(#H)'^\h'|\\n:u' . ds , \\k:\h'-(\\n(.wu*8/10)',\h'|\\n:u' . ds ~ \\k:\h'-(\\n(.wu-\*(#H-.1m)'~\h'|\\n:u' . ds / \\k:\h'-(\\n(.wu*8/10-\*(#H)'\z\(sl\h'|\\n:u' .\} . \" troff and (daisy-wheel) nroff accents .ds : \\k:\h'-(\\n(.wu*8/10-\*(#H+.1m+\*(#F)'\v'-\*(#V'\z.\h'.2m+\*(#F'.\h'|\\n:u'\v'\*(#V' .ds 8 \h'\*(#H'\(*b\h'-\*(#H' .ds o \\k:\h'-(\\n(.wu+\w'\(de'u-\*(#H)/2u'\v'-.3n'\*(#[\z\(de\v'.3n'\h'|\\n:u'\*(#] .ds d- \h'\*(#H'\(pd\h'-\w'~'u'\v'-.25m'\f2\(hy\fP\v'.25m'\h'-\*(#H' .ds D- D\\k:\h'-\w'D'u'\v'-.11m'\z\(hy\v'.11m'\h'|\\n:u' .ds th \*(#[\v'.3m'\s+1I\s-1\v'-.3m'\h'-(\w'I'u*2/3)'\s-1o\s+1\*(#] .ds Th \*(#[\s+2I\s-2\h'-\w'I'u*3/5'\v'-.3m'o\v'.3m'\*(#] .ds ae a\h'-(\w'a'u*4/10)'e .ds Ae A\h'-(\w'A'u*4/10)'E . \" corrections for vroff .if v .ds ~ \\k:\h'-(\\n(.wu*9/10-\*(#H)'\s-2\u~\d\s+2\h'|\\n:u' .if v .ds ^ \\k:\h'-(\\n(.wu*10/11-\*(#H)'\v'-.4m'^\v'.4m'\h'|\\n:u' . \" for low resolution devices (crt and lpr) .if \n(.H>23 .if \n(.V>19 \ \{\ . ds : e . ds 8 ss . ds o a . ds d- d\h'-1'\(ga . ds D- D\h'-1'\(hy . ds th \o'bp' . ds Th \o'LP' . ds ae ae . ds Ae AE .\} .rm #[ #] #H #V #F C .\" ======================================================================== .\" .IX Title "Catmandu::Importer::getJSON 3pm" .TH Catmandu::Importer::getJSON 3pm "2022-12-10" "perl v5.36.0" "User Contributed Perl Documentation" .\" For nroff, turn off justification. Always turn off hyphenation; it makes .\" way too many mistakes in technical documents. .if n .ad l .nh .SH "NAME" Catmandu::Importer::getJSON \- load JSON\-encoded data from a server using a GET HTTP request .SH "SYNOPSIS" .IX Header "SYNOPSIS" The following three examples are equivalent: .PP .Vb 3 \& Catmandu::Importer::getJSON\->new( \& file => \e"http://example.org/alice.json\enhttp://example.org/bob.json" \& )\->each(sub { my ($record) = @_; ... ); \& \& Catmandu::Importer::getJSON\->new( \& url => "http://example.org", \& file => \e"/alice.json\en/bob.json" \& )\->each(sub { my ($record) = @_; ... ); \& \& Catmandu::Importer::getJSON\->new( \& url => "http://example.org/{name}.json", \& file => \e"{\e"name\e":\e"alice\e"}\en{\e"name\e":\e"bob\e"}" \& )\->each(sub { my ($record) = @_; ... ); .Ve .PP For more convenience the catmandu command line client can be used: .PP .Vb 3 \& echo http://example.org/alice.json | catmandu convert getJSON to YAML \& catmandu convert getJSON \-\-from http://example.org/alice.json to YAML \& catmandu convert getJSON \-\-dry 1 \-\-url http://{domain}/robots.txt < domains .Ve .SH "DESCRIPTION" .IX Header "DESCRIPTION" This Catmandu::Importer performs a \s-1HTTP GET\s0 request to load JSON-encoded data from a server. The importer expects a line-separated input. Each line corresponds to a \s-1HTTP\s0 request that is mapped to a JSON-record on success. The following input formats are accepted: .IP "plain \s-1URL\s0" 4 .IX Item "plain URL" A line that starts with "\f(CW\*(C`http://\*(C'\fR\*(L" or \*(R"\f(CW\*(C`https://\*(C'\fR" is used as plain \s-1URL.\s0 .IP "\s-1URL\s0 path" 4 .IX Item "URL path" A line that starts with "\f(CW\*(C`/\*(C'\fR" is appended to the configured \fBurl\fR parameter. .IP "variables" 4 .IX Item "variables" A \s-1JSON\s0 object with variables to be used with an \s-1URL\s0 template or as \s-1HTTP\s0 query parameters. For instance the input line \f(CW\*(C`{"name":"Karl Marx"}\*(C'\fR with \s-1URL\s0 \&\f(CW\*(C`http://api.lobid.org/person\*(C'\fR or the input line \&\f(CW\*(C`{"entity":"person","name":"Karl Marx"}\*(C'\fR with \s-1URL\s0 template \&\f(CW\*(C`http://api.lobid.org/{entity}{?id}{?name}{?q}\*(C'\fR are both expanded to . .PP If the \s-1JSON\s0 data returned in a \s-1HTTP\s0 response is a \s-1JSON\s0 array, its elements are imported as multiple items. If a \s-1JSON\s0 object is returned, it is imported as one item. .SH "CONFIGURATION" .IX Header "CONFIGURATION" .IP "url" 4 .IX Item "url" An \s-1URI\s0 or an \s-1URI\s0 templates (URI::Template) as defined by \&\s-1RFC 6570\s0 to load \s-1JSON\s0 from. If no \fBurl\fR is configured, plain URLs must be provided as input or option \f(CW\*(C`from\*(C'\fR must be used instead. .IP "from" 4 .IX Item "from" A plain \s-1URL\s0 to load \s-1JSON\s0 without reading any input lines. .IP "timeout / agent / proxy / headers" 4 .IX Item "timeout / agent / proxy / headers" Optional \s-1HTTP\s0 client settings. .IP "client" 4 .IX Item "client" Instance of a Furl \s-1HTTP\s0 client to perform requests with. .IP "dry" 4 .IX Item "dry" Don't do any \s-1HTTP\s0 requests but return URLs that data would be queried from. .IP "file / fh" 4 .IX Item "file / fh" Input to read lines from (see Catmandu::Importer). Defaults to \s-1STDIN.\s0 .IP "fix" 4 .IX Item "fix" An optional fix to be applied on every item (see Catmandu::Fix). .IP "wait" 4 .IX Item "wait" Number of seconds to wait between requests. .IP "cache" 4 .IX Item "cache" Cache \s-1JSON\s0 response of URLs to not request the same \s-1URL\s0 twice. \s-1HTTP\s0 error codes in the 4xx range (e.g. 404) are also cached but 5xx errors are not. .Sp The value of this option can be any objects that implements method \f(CW\*(C`get\*(C'\fR and \&\f(CW\*(C`set\*(C'\fR (e.g. \f(CW\*(C`CHI\*(C'\fR), an existing directory for file caching, a true value to enable global in-memory-caching, or a false value to disable caching (default). .Sp File caching uses file names based on \s-1MD5\s0 of an \s-1URL\s0 so for instance \&\f(CW\*(C`http://example.org/\*(C'\fR is cached as \f(CW\*(C`4389382917e51695b759543fdfd5f690.json\*(C'\fR. .IP "warn" 4 .IX Item "warn" Show error messages on the standard error. .SH "METHODS" .IX Header "METHODS" .SS "time" .IX Subsection "time" Returns the \s-1UNIX\s0 timestamp right before the last request. This can be used for instance to add timestamps or the measure how fast requests were responded. .ie n .SS "construct_url( [ $base_url, ] $vars_url_or_path )" .el .SS "construct_url( [ \f(CW$base_url\fP, ] \f(CW$vars_url_or_path\fP )" .IX Subsection "construct_url( [ $base_url, ] $vars_url_or_path )" Returns an \s-1URL\s0 given a hash reference with variables, a plain \s-1URL\s0 or an \s-1URL\s0 path. The optional first argument can be used to override option \f(CW\*(C`url\*(C'\fR. .PP .Vb 2 \& $importer\->construct_url( %query_vars ) \& $importer\->construct_url( $importer\->url, %query_vars ) # equivalent .Ve .SS "request($url)" .IX Subsection "request($url)" Perform a \s-1HTTP GET\s0 request of a given \s-1URL\s0 including logging, caching, request hook etc. Returns a hash/array reference or \f(CW\*(C`undef\*(C'\fR. .SH "EXTENDING" .IX Header "EXTENDING" This importer provides two methods to filter requests and responses, respectively. See Catmandu::Importer::Wikidata for an example. .SS "request_hook" .IX Subsection "request_hook" Gets a whitespace-trimmed input line and is expected to return an unblessed hash reference, an \s-1URL,\s0 or undef. Errors are catched and treated equal to undef. .SS "response_hook" .IX Subsection "response_hook" Gets the queried response object and is expected to return an object. .SH "LOGGING" .IX Header "LOGGING" URLs are emitted before each request on \s-1DEBUG\s0 log level. .SH "LIMITATIONS" .IX Header "LIMITATIONS" Future versions of this module may also support asynchronous \s-1HTTP\s0 fetching modules such as HTTP::Async, for retrieving multiple URLs at the same time. .SH "SEE ALSO" .IX Header "SEE ALSO" Catmandu::Fix::get_json provides this importer as fix function. .SH "COPYRIGHT AND LICENSE" .IX Header "COPYRIGHT AND LICENSE" Copyright Jakob Vo\*8, 2014\- .PP This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself.