Search::Elasticsearch::Role::Serializer::JSON(3pm)

Search::Elasticsearch::Role::Serializer::JSON3pm

A serializer role for json modules

Version

version 8.12

Overview

This role encodes Perl data structures into JSON strings, and decodes JSON strings into Perl data structures.

Methods

encode()

    $bytes = $serializer->encode($ref);
    $bytes = $serializer->encode($str);

The "encode()" 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 "undef" are returned as is.

encode_pretty()

    $bytes = $serializer->encode_pretty($ref);
    $bytes = $serializer->encode_pretty($str);

Works exactly as "encode()" but the JSON output is pretty-printed.

encode_bulk()

    $bytes = $serializer->encode_bulk([\%hash,\%hash,...]);
    $bytes = $serializer->encode_bulk([$str,$str,...]);

The "encode_bulk()" method expects an array ref of hashes or strings. Each hash or string is processed by "encode()" 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.

decode()

    $var = $serializer->decode($json_bytes);
    $str = $serializer->decode($bytes);

If the passed in value looks like JSON (ie starts with a "{" or "[" character), then it is decoded from JSON, otherwise it is returned as the UTF8 decoded version of itself. The empty string and "undef" are returned as is.

Releases

5 releases since Debian 9 (Stretch); the text changed 4 times.

  1. 9
  2. 10
  3. 11
  4. 12
  5. 13

Author

Enrico Zimuel <[email protected]>

From libsearch-elasticsearch-perl 8.12-1 in Debian 13 (Trixie). Parsed by carta from the page's man source.