.\" -*- mode: troff; coding: utf-8 -*- .\" Automatically generated by Pod::Man 5.01 (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 .. .\" \*(C` and \*(C' are quotes in nroff, nothing in troff, for use with C<>. .ie n \{\ . ds C` "" . ds C' "" 'br\} .el\{\ . 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 .\" ======================================================================== .\" .IX Title "Search::Elasticsearch::Role::Serializer::JSON 3pm" .TH Search::Elasticsearch::Role::Serializer::JSON 3pm 2024-02-04 "perl v5.38.2" "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 Search::Elasticsearch::Role::Serializer::JSON \- A Serializer role for JSON modules .SH VERSION .IX Header "VERSION" version 8.12 .SH DESCRIPTION .IX Header "DESCRIPTION" This role encodes Perl data structures into JSON strings, and decodes JSON strings into Perl data structures. .SH METHODS .IX Header "METHODS" .ie n .SS encode() .el .SS \f(CWencode()\fP .IX Subsection "encode()" .Vb 2 \& $bytes = $serializer\->encode($ref); \& $bytes = $serializer\->encode($str); .Ve .PP The "\fBencode()\fR" method converts array and hash refs into their JSON equivalents. If a string is passed in, it is returned as the UTF8 encoded version of itself. The empty string and \f(CW\*(C`undef\*(C'\fR are returned as is. .ie n .SS encode_pretty() .el .SS \f(CWencode_pretty()\fP .IX Subsection "encode_pretty()" .Vb 2 \& $bytes = $serializer\->encode_pretty($ref); \& $bytes = $serializer\->encode_pretty($str); .Ve .PP Works exactly as "\fBencode()\fR" but the JSON output is pretty-printed. .ie n .SS encode_bulk() .el .SS \f(CWencode_bulk()\fP .IX Subsection "encode_bulk()" .Vb 2 \& $bytes = $serializer\->encode_bulk([\e%hash,\e%hash,...]); \& $bytes = $serializer\->encode_bulk([$str,$str,...]); .Ve .PP The "\fBencode_bulk()\fR" method expects an array ref of hashes or strings. Each hash or string is processed by "\fBencode()\fR" then joined together by newline characters, with a final newline character appended to the end. This is the special JSON format used for bulk requests. .ie n .SS decode() .el .SS \f(CWdecode()\fP .IX Subsection "decode()" .Vb 2 \& $var = $serializer\->decode($json_bytes); \& $str = $serializer\->decode($bytes); .Ve .PP If the passed in value looks like JSON (ie starts with a \f(CW\*(C`{\*(C'\fR or \f(CW\*(C`[\*(C'\fR character), then it is decoded from JSON, otherwise it is returned as the UTF8 decoded version of itself. The empty string and \f(CW\*(C`undef\*(C'\fR are returned as is. .SH AUTHOR .IX Header "AUTHOR" Enrico Zimuel .SH "COPYRIGHT AND LICENSE" .IX Header "COPYRIGHT AND LICENSE" This software is Copyright (c) 2024 by Elasticsearch BV. .PP This is free software, licensed under: .PP .Vb 1 \& The Apache License, Version 2.0, January 2004 .Ve