NAME
Langertha::Role::JSON - Role for JSON
VERSION
version 0.503
decode_json_text
my $data = $engine->decode_json_text($perl_string);
Decodes a JSON string that is already a Perl-Unicode string (e.g. a value pulled out of an already-decoded response tree, or a substring extracted from assistant-produced text). The shared JSON::MaybeXS instance is configured with utf8 => 1 and expects raw bytes, so this helper UTF-8-encodes the text before delegating to it. Use this instead of $self->json->decode whenever the source is Perl-Unicode rather than the raw HTTP body.
encode_json_text
my $text = $engine->encode_json_text($data);
The mirror of "decode_json_text": encodes $data to a JSON character string, for JSON that travels as a string value inside another JSON document or inside prompt text (a hermes tool prompt, AKI's chat_context, a lifted structured-output content). The request body is encoded to UTF-8 bytes exactly once, by "json" at the transport; a nested value encoded to bytes here would be encoded a second time there. Same settings as "json" (canonical, convert_blessed).
json
my $data = $engine->json->decode($json_string);
my $json_string = $engine->json->encode($data);
Returns the shared JSON::MaybeXS instance configured with utf8, canonical, and convert_blessed encoding. Used internally by Langertha::Role::HTTP and Langertha::Role::Streaming for all JSON serialization. convert_blessed means the distribution's value objects (with their TO_JSON methods) serialize through this encoder instead of croaking.
SEE ALSO
Langertha::Role::HTTP - HTTP role that requires this
JSON::MaybeXS - The JSON backend used
SUPPORT
Issues
Please report bugs and feature requests on GitHub at https://github.com/Getty/langertha/issues.
IRC
Join #langertha on irc.perl.org or message Getty directly.
CONTRIBUTING
Contributions are welcome! Please fork the repository and submit a pull request.
AUTHOR
Torsten Raudssus <getty@cpan.org>
COPYRIGHT AND LICENSE
This software is copyright (c) 2026 by Torsten Raudssus https://raudssus.de/.
This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself.