in reply to strings to json
It's best to use one of the JSON modules. For example JSON::Tiny, but also JSON::XS or JSON or JSON::Any.
use strict; use JSON::Tiny 'encode_json'; my $name = 'mike'; my $age = "20"; my $email = "johndeo@/test.com"; my $pass = "test"; my $resp = { $name => $age, $email => $pass }; print encode_json( $resp );
Your JSON strikes me as weird. I would expect a different JSON structure:
my $resp = { name => $name, age => $age, email => $email, pass => $pass, };
|
|---|