How to un-prettify JSON?
Hello, I just upgraded from Dancer 1.2 to latest (1.3XX) and my JSON output changed from un-pretty to pretty. set serializer => 'JSON'; get '/products' => sub { return db_products(); }; I see the option in the docs but cannot figure out how to use it. In "config.yml", I tried : engines: JSON: pretty: 0 But that makes no difference. How do I turn off "pretty"? Cheers, -- Alastair Sherringham http://www.sherringham.net
On Mar 13, 2011, at 5:29 AM, Alastair Sherringham wrote:
Hello,
I just upgraded from Dancer 1.2 to latest (1.3XX) and my JSON output changed from un-pretty to pretty.
set serializer => 'JSON'; get '/products' => sub { return db_products(); };
I see the option in the docs but cannot figure out how to use it. In "config.yml", I tried :
engines: JSON: pretty: 0
But that makes no difference. How do I turn off "pretty"?
I asked the same question on Feb 27, but didn't get any definitive answer. I would also love to "unprettify" the JSON output so it is more compact. Thanks, Puneet.
On 13 March 2011 09:29, Alastair Sherringham <sherringham@gmail.com> wrote:
set serializer => 'JSON'; get '/products' => sub { return db_products(); };
If I replace the above with : get '/products' => sub { my $product_list = db_products(); content_type 'application/json'; return to_json($product_list,{ pretty => 0}); }; It works - non-pretty-printed JSON. This is actually documented in Dancer.pm (to_json section) : http://search.cpan.org/dist/Dancer/lib/Dancer.pm#to_json_%28$structure,_%opt... So, my error on missing that. Cheers, -- Alastair Sherringham http://www.sherringham.net
On Mar 13, 2011, at 8:19 AM, Alastair Sherringham wrote:
On 13 March 2011 09:29, Alastair Sherringham <sherringham@gmail.com> wrote:
set serializer => 'JSON'; get '/products' => sub { return db_products(); };
If I replace the above with :
get '/products' => sub { my $product_list = db_products(); content_type 'application/json'; return to_json($product_list,{ pretty => 0}); };
It works - non-pretty-printed JSON.
This is actually documented in Dancer.pm (to_json section) :
http://search.cpan.org/dist/Dancer/lib/Dancer.pm#to_json_%28$structure,_%opt...
So, my error on missing that. ..
Oh! fantastic! I would venture that the above is "hidden" in the documentation. Adding your text above to the documentation would be even more clear and explicit -- clear and explicit instructions are always better than hidden and implicit instructions. Many thanks for the investigation. Puneet.
Hi, I've checked the code and apparently pretty printing is only on if you're in the "development" dancefloor. :) Sawyer.
On Mar 13, 2011, at 12:40 PM, sawyer x wrote:
Hi,
I've checked the code and apparently pretty printing is only on if you're in the "development" dancefloor. :)
Ok. I am "supposedly" on the development dancefloor, so perhaps that is why I am getting prettified JSON, although I would like to make it more compact, and now I can. But, see my email from Mar 5. I reproduce it below. As the following email details, I have been under the impression that I just can't get the development environment to kick in under Apache. One of the results of this effect is that I don't get anything in my development.log. If I use the Dancer built-in server, I am able to see messages in development.log, however, if I were to use the built-in server, the built-in server doesn't allow me to set aliases to directories (another query that I posted on Mar 5 was on this issue -- no resolution of that as yet). ---- I can't figure out how to tell Dancer that my app should use development.yml under Apache. I have the following in vhosts.conf SetEnv DANCER_ENVIRONMENT "development" When I put the following fragment in config.yml, everything works db_name: "mydb" db_user: "dev" db_pass: "dev" When I take the above fragment out of config.yml, and put it in development.yml, all the config->{} values are empty. For example, I get the following error in my Apache log DBI connect('dbname=','',...) failed: FATAL: because, my code is my $dbh = DBI->connect( "dbi:Pg:dbname=" . config->{db_name}, config->{db_user}, config->{db_pass}, {AutoCommit => 0} ); If I put the above in development.yml, and put the following in production.yml, it fails because it can't find the prod databases db_name: "mydb" db_user: "prod" db_pass: "prod" It is almost as if development.yml is not being seen at all. It is being bypassed. Maybe that also explains why I am not getting any development.log. Any ideas? I am using Dancer 1.3011. Puneet,
could you try to set PLACK_ENV to development inside your apache configuration (if you're using plack of course) On Sun, Mar 13, 2011 at 8:26 PM, Mr. Puneet Kishor <punk.kish@gmail.com>wrote:
On Mar 13, 2011, at 12:40 PM, sawyer x wrote:
Hi,
I've checked the code and apparently pretty printing is only on if you're in the "development" dancefloor. :)
Ok. I am "supposedly" on the development dancefloor, so perhaps that is why I am getting prettified JSON, although I would like to make it more compact, and now I can.
But, see my email from Mar 5. I reproduce it below. As the following email details, I have been under the impression that I just can't get the development environment to kick in under Apache. One of the results of this effect is that I don't get anything in my development.log.
If I use the Dancer built-in server, I am able to see messages in development.log, however, if I were to use the built-in server, the built-in server doesn't allow me to set aliases to directories (another query that I posted on Mar 5 was on this issue -- no resolution of that as yet).
---- I can't figure out how to tell Dancer that my app should use development.yml under Apache.
I have the following in vhosts.conf
SetEnv DANCER_ENVIRONMENT "development"
When I put the following fragment in config.yml, everything works
db_name: "mydb" db_user: "dev" db_pass: "dev"
When I take the above fragment out of config.yml, and put it in development.yml, all the config->{} values are empty. For example, I get the following error in my Apache log
DBI connect('dbname=','',...) failed: FATAL:
because, my code is
my $dbh = DBI->connect( "dbi:Pg:dbname=" . config->{db_name}, config->{db_user}, config->{db_pass}, {AutoCommit => 0} );
If I put the above in development.yml, and put the following in production.yml, it fails because it can't find the prod databases
db_name: "mydb" db_user: "prod" db_pass: "prod"
It is almost as if development.yml is not being seen at all. It is being bypassed. Maybe that also explains why I am not getting any development.log.
Any ideas? I am using Dancer 1.3011.
Puneet, _______________________________________________ Dancer-users mailing list Dancer-users@perldancer.org http://www.backup-manager.org/cgi-bin/listinfo/dancer-users
-- franck cuny http://lumberjaph.net - http://github.com/franckcuny
On Mar 13, 2011, at 2:33 PM, franck wrote:
could you try to set PLACK_ENV to development inside your apache configuration (if you're using plack of course)
Sorry, I am not using plack.
On Sun, Mar 13, 2011 at 8:26 PM, Mr. Puneet Kishor <punk.kish@gmail.com> wrote:
On Mar 13, 2011, at 12:40 PM, sawyer x wrote:
Hi,
I've checked the code and apparently pretty printing is only on if you're in the "development" dancefloor. :)
Ok. I am "supposedly" on the development dancefloor, so perhaps that is why I am getting prettified JSON, although I would like to make it more compact, and now I can.
But, see my email from Mar 5. I reproduce it below. As the following email details, I have been under the impression that I just can't get the development environment to kick in under Apache. One of the results of this effect is that I don't get anything in my development.log.
If I use the Dancer built-in server, I am able to see messages in development.log, however, if I were to use the built-in server, the built-in server doesn't allow me to set aliases to directories (another query that I posted on Mar 5 was on this issue -- no resolution of that as yet).
---- I can't figure out how to tell Dancer that my app should use development.yml under Apache.
I have the following in vhosts.conf
SetEnv DANCER_ENVIRONMENT "development"
When I put the following fragment in config.yml, everything works
db_name: "mydb" db_user: "dev" db_pass: "dev"
When I take the above fragment out of config.yml, and put it in development.yml, all the config->{} values are empty. For example, I get the following error in my Apache log
DBI connect('dbname=','',...) failed: FATAL:
because, my code is
my $dbh = DBI->connect( "dbi:Pg:dbname=" . config->{db_name}, config->{db_user}, config->{db_pass}, {AutoCommit => 0} );
If I put the above in development.yml, and put the following in production.yml, it fails because it can't find the prod databases
db_name: "mydb" db_user: "prod" db_pass: "prod"
It is almost as if development.yml is not being seen at all. It is being bypassed. Maybe that also explains why I am not getting any development.log.
Any ideas? I am using Dancer 1.3011.
Puneet, _______________________________________________ Dancer-users mailing list Dancer-users@perldancer.org http://www.backup-manager.org/cgi-bin/listinfo/dancer-users
-- franck cuny http://lumberjaph.net - http://github.com/franckcuny
could you try to set PLACK_ENV to development inside your apache configuration (if you're using plack of course)
Sorry, I am not using plack.
ok, so there is an issue somewhere else :/ will try to reproduce the issue.
On Sun, Mar 13, 2011 at 8:26 PM, Mr. Puneet Kishor <punk.kish@gmail.com> wrote:
On Mar 13, 2011, at 12:40 PM, sawyer x wrote:
Hi,
I've checked the code and apparently pretty printing is only on if you're in the "development" dancefloor. :)
Ok. I am "supposedly" on the development dancefloor, so perhaps that is why I am getting prettified JSON, although I would like to make it more compact, and now I can.
But, see my email from Mar 5. I reproduce it below. As the following email details, I have been under the impression that I just can't get the development environment to kick in under Apache. One of the results of this effect is that I don't get anything in my development.log.
If I use the Dancer built-in server, I am able to see messages in development.log, however, if I were to use the built-in server, the built-in server doesn't allow me to set aliases to directories (another query that I posted on Mar 5 was on this issue -- no resolution of that as yet).
---- I can't figure out how to tell Dancer that my app should use development.yml under Apache.
I have the following in vhosts.conf
SetEnv DANCER_ENVIRONMENT "development"
When I put the following fragment in config.yml, everything works
db_name: "mydb" db_user: "dev" db_pass: "dev"
When I take the above fragment out of config.yml, and put it in development.yml, all the config->{} values are empty. For example, I get the following error in my Apache log
DBI connect('dbname=','',...) failed: FATAL:
because, my code is
my $dbh = DBI->connect( "dbi:Pg:dbname=" . config->{db_name}, config->{db_user}, config->{db_pass}, {AutoCommit => 0} );
If I put the above in development.yml, and put the following in production.yml, it fails because it can't find the prod databases
db_name: "mydb" db_user: "prod" db_pass: "prod"
It is almost as if development.yml is not being seen at all. It is being bypassed. Maybe that also explains why I am not getting any development.log.
Any ideas? I am using Dancer 1.3011.
Puneet, _______________________________________________ Dancer-users mailing list Dancer-users@perldancer.org http://www.backup-manager.org/cgi-bin/listinfo/dancer-users
-- franck cuny http://lumberjaph.net - http://github.com/franckcuny
_______________________________________________ Dancer-users mailing list Dancer-users@perldancer.org http://www.backup-manager.org/cgi-bin/listinfo/dancer-users
-- franck cuny http://lumberjaph.net - http://github.com/franckcuny
On Mon, 2011-03-14 at 20:29 +0000, franck wrote:
> could you try to set PLACK_ENV to development inside your apache configuration (if you're using plack of course) >
Sorry, I am not using plack.
ok, so there is an issue somewhere else :/
We've had this issue as well - our service definitely isn't in development mode :) but i've found this: in Dancer::Config.pm $SETTINGS->{environment} ||= $ENV{DANCER_ENVIRONMENT} || $ENV{PLACK_ENV} || 'development'; which looks like it might be doing it. Alex
will try to reproduce the issue.
> On Sun, Mar 13, 2011 at 8:26 PM, Mr. Puneet Kishor <punk.kish@gmail.com> wrote: > > On Mar 13, 2011, at 12:40 PM, sawyer x wrote: > > > Hi, > > > > I've checked the code and apparently pretty printing is only on if you're in the "development" dancefloor. :) > > > > > > Ok. I am "supposedly" on the development dancefloor, so perhaps that is why I am getting prettified JSON, although I would like to make it more compact, and now I can. > > But, see my email from Mar 5. I reproduce it below. As the following email details, I have been under the impression that I just can't get the development environment to kick in under Apache. One of the results of this effect is that I don't get anything in my development.log. > > If I use the Dancer built-in server, I am able to see messages in development.log, however, if I were to use the built-in server, the built-in server doesn't allow me to set aliases to directories (another query that I posted on Mar 5 was on this issue -- no resolution of that as yet). > > ---- > I can't figure out how to tell Dancer that my app should use development.yml under Apache. > > I have the following in vhosts.conf > > SetEnv DANCER_ENVIRONMENT "development" > > When I put the following fragment in config.yml, everything works > > db_name: "mydb" > db_user: "dev" > db_pass: "dev" > > When I take the above fragment out of config.yml, and put it in development.yml, all the config->{} values are empty. For example, I get the following error in my Apache log > > DBI connect('dbname=','',...) failed: FATAL: > > because, my code is > > my $dbh = DBI->connect( > "dbi:Pg:dbname=" . config->{db_name}, > config->{db_user}, > config->{db_pass}, > {AutoCommit => 0} > ); > > If I put the above in development.yml, and put the following in production.yml, it fails because it can't find the prod databases > > db_name: "mydb" > db_user: "prod" > db_pass: "prod" > > It is almost as if development.yml is not being seen at all. It is being bypassed. Maybe that also explains why I am not getting any development.log. > > Any ideas? I am using Dancer 1.3011. > > Puneet, > _______________________________________________ > Dancer-users mailing list > Dancer-users@perldancer.org > http://www.backup-manager.org/cgi-bin/listinfo/dancer-users > > > > -- > franck cuny > http://lumberjaph.net - http://github.com/franckcuny >
_______________________________________________ Dancer-users mailing list Dancer-users@perldancer.org http://www.backup-manager.org/cgi-bin/listinfo/dancer-users
-- franck cuny http://lumberjaph.net - http://github.com/franckcuny
On Mar 14, 2011, at 3:29 PM, franck wrote:
could you try to set PLACK_ENV to development inside your apache configuration (if you're using plack of course)
Sorry, I am not using plack.
ok, so there is an issue somewhere else :/
will try to reproduce the issue.
Figured it out. I believe since 1.30xx onward, we have the following in dispatch.cgi ---- #!/usr/local/bin/perl use Dancer ':syntax'; use FindBin '$RealBin'; use Plack::Runner; # For some reason Apache SetEnv directives dont propagate # correctly to the dispatchers, so forcing PSGI and env here # is safer. set apphandler => 'PSGI'; *** set environment => 'production'; ---- The line marked with *** sets the default environment to "production". This is coming from the "dancer -a" bootstrapping program which writes out "dispatch.cgi" around line 596. This line was forcing my app to always be in production, ignoring any other settings, for example, the settings in my apache conf file. Puneet.
On Mar 16, 2011, at 12:28 AM, Mr. Puneet Kishor wrote:
On Mar 14, 2011, at 3:29 PM, franck wrote:
could you try to set PLACK_ENV to development inside your apache configuration (if you're using plack of course)
Sorry, I am not using plack.
ok, so there is an issue somewhere else :/
will try to reproduce the issue.
Figured it out. I believe since 1.30xx onward, we have the following in dispatch.cgi
---- #!/usr/local/bin/perl use Dancer ':syntax'; use FindBin '$RealBin'; use Plack::Runner;
# For some reason Apache SetEnv directives dont propagate # correctly to the dispatchers, so forcing PSGI and env here # is safer. set apphandler => 'PSGI'; *** set environment => 'production'; ----
The line marked with *** sets the default environment to "production". This is coming from the "dancer -a" bootstrapping program which writes out "dispatch.cgi" around line 596.
Line 491, not 596.
This line was forcing my app to always be in production, ignoring any other settings, for example, the settings in my apache conf file.
Puneet.
participants (6)
-
Alastair Sherringham -
Alex Knowles -
franck -
Mr. Puneet Kishor -
Mr. Puneet Kishor -
sawyer x