NAME
API::Docker::Role::JSONBody - coerce known boolean keys of a request body to JSON booleans
VERSION
version 0.004
DESCRIPTION
The Docker Engine type-checks a JSON request body: a field the swagger declares boolean must arrive as a JSON true/false, and a number in its place is rejected outright. Measured non-mutating against Docker 29.7.2 (API 1.55), POST /containers/no-such/exec with {"Cmd":["true"],"AttachStdout":1} answers 400 json: cannot unmarshal number into Go struct field ... of type bool; Podman 5.8.4 (compat API 1.44) answers 500 with the same Go message. The query string is not type-checked, which is why 1/0 is right there and wrong here.
Every resource API that forwards a caller HashRef as a JSON body therefore normalises its own boolean keys on the way out, the same \1/\0 encoding "start" in API::Docker::API::Exec already used. Which keys are boolean is the swagger's answer and belongs to each method (the sets are declared beside the call); this role carries only the mechanical coercion they share.
_json_bools
$self->_json_bools(\%body, qw( Tty OpenStdin AttachStdout ));
Coerce the named keys of $hash in place to JSON booleans and return the same HashRef. A key that is absent is left alone (so an unset option sends nothing), and a value that is already a reference -- a \1/\0 or a JSON::PP::Boolean -- is left as it is, which keeps the coercion idempotent and lets a caller who already passes JSON->true through untouched. Any other value becomes \1 when true and \0 when false, so a caller passing 1/0 gets a real JSON boolean on the wire.
This mutates the HashRef it is given, so a caller normalising a nested sub-object (a HostConfig, say) must hand it a copy it owns rather than the caller's own nested HashRef.
SUPPORT
Issues
Please report bugs and feature requests on GitHub at https://github.com/Getty/p5-api-docker/issues.
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 <torsten@raudssus.de> 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.