in reply to strings to json

What's your expected output? Because here it kind of looks like you want:

{ "mike":20, "johndeo@/test.com":test }
which doesn't make much sense.

One easy way to make json structure in perl, is to simple encore perl structures using JSON:

use JSON; my %data = (name => "Mike", age => 20, email => "mike@perlmonks.org", +pass => "IAmGroot"); print encode_json(\%data); #edited thanks to marto __DATA__ {"age":20,"pass":"IAmGroot","email":"mike.org","name":"Mike"}

NB: be careful with double quotes, @ should be interpreted as the sigil of an array variable, even though here it is not for some reason. Simple quotes would be better.

Edit: the fact that @/ (a punctuation variable) is not interpolated is actually documented in perlop

"Punctuation" arrays such as @* are usually interpolated only if the name is enclosed in braces @{*}, but the arrays @_ , @+ , and @- are interpolated even without braces.

Replies are listed 'Best First'.
Re^2: strings to json
by marto (Cardinal) on Jun 23, 2017 at 13:47 UTC

    encore_json should be encode_json.