in reply to strings to json
This will work:
use strict; use warnings; my $name = 'mike'; my $age = "20"; my $email = "johndeo\@test.com"; my $pass = "test"; my $resp = "{ \"$name\": $age, \"$email\": \"$pass\" }"; print $resp;
But escaping is likely to be annoying. I'd personally do something more like this:
use strict; use warnings; use JSON::PP; my $name = 'mike'; my $age = "20"; my $email = "johndeo\@test.com"; my $pass = "test"; my $resp = JSON::PP->new->encode({ $name => $age, $email => $pass, }); print $resp;
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: strings to json
by ikegami (Patriarch) on Jun 23, 2017 at 15:06 UTC | |
by tobyink (Canon) on Jun 24, 2017 at 21:51 UTC | |
by ikegami (Patriarch) on Jun 25, 2017 at 03:35 UTC | |
by Anonymous Monk on Jun 25, 2017 at 03:44 UTC | |
by ikegami (Patriarch) on Jun 25, 2017 at 03:46 UTC | |
| |
|
Re^2: strings to json
by bigup401 (Pilgrim) on Jun 23, 2017 at 13:57 UTC |