Question: According to:

<http://search.cpan.org/~drolsky/DateTime-1.43/lib/DateTime.pm#Formatters_And_Stringification>

the following will work:

```
use DateTime;
$dt = DateTime->new( ... );
print $dt;  # as string

```

and it does. 

However, when using the JSON module to embed the created $dt string as a json-encoded data structure as follows:

```
use JSON;
my $json = JSON::encode_json( { dt => $dt } );

```

The JSON module is throwing the following exception:

```
encountered object '2017-08-02', but neither allow_blessed nor convert_blessed settings are enabled at ...

```

I can work around the issue as follows:

```
my $json = JSON::encode_json( { dt => substr($dt,0) } );

```

but wonder if there's a cleaner way to get a "true" string out of DateTime? 

I've looked through the DateTime docs but I don't see an explicit stringify() to create the true string as required by JSON.

EDIT: In the constructor, I specify a desired output format via 'formatter'. I'd like to get a string using the already-specified format, and not specify the format again (which would be against DRY principle...)

EDIT2: Interpolating the string is a good solution if just $dt, but doesn't work if $dt is actually a moose attribute (i.e. "$person->birth\_d").

Answer: 
You can use `"$dt"` or `"".$o->dt`. Like your solution, it's short for

```
$dt->formatter ? $dt->formatter->format_datetime($dt) : $dt->iso8601

```

If you want a specific format, there's `$dt->strftime`, `$dt->iso8601`, or you could use a [*DateTime::Format::*](http://search.cpan.org/search?query=DateTime%3A%3AFormat&mode=module) module.
You can explicitly interpolate the object in a string (`"$dt"`) or call the method that's actually getting called (`$dt->iso8601`).

```
use strict;
use warnings;
use 5.010;

use DateTime;

my $dt = DateTime->now;

say $dt;
say "$dt";
say $dt->iso8601;

```

Output:

```
2017-08-02T19:54:22
2017-08-02T19:54:22
2017-08-02T19:54:22

```