Beefy Boxes and Bandwidth Generously Provided by pair Networks
Syntactic Confectionery Delight

Re: Interpolating variables in JSON string

by muba (Priest)
on Jan 29, 2013 at 13:52 UTC ( #1015876=note: print w/ replies, xml ) Need Help??

in reply to Interpolating variables in JSON string

The line

my $json = quotemeta( {"auth":{"RAX-KSKEY:apiKeyCredentials":{"use +rname":$USERNAME, "apiKey":$API_KEY}}} );
makes no sense. The character : is only part of the Perl syntax in rather specific places, and this isn't one of them. I get a syntax error message for this line.

The Perl equivalent of a JSON map is called a hash. Traditionally we use => to separate keys from their values, not :.

my $json = quotemeta( {"auth" => {"RAX-KSKEY:apiKeyCredentials" => + {"username" => $USERNAME, "apiKey" => $API_KEY}}} );

But even that would make little sense. That line would make the data structure, return a reference to it, try to quotemeta that reference, and store that in $json. So $json would end up being something like "HASH\(0x33c218\)". You don't need quotemeta here — you only need quotemeta when you're about to use a string inside a regular expressions and you're afraid that your string might have regex meta characters while you actually want to match them literally. What you do need is a real JSON module, like the good monks before me already suggested.

Comment on Re: Interpolating variables in JSON string
Select or Download Code

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1015876]
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others imbibing at the Monastery: (3)
As of 2015-11-29 11:29 GMT
Find Nodes?
    Voting Booth?

    What would be the most significant thing to happen if a rope (or wire) tied the Earth and the Moon together?

    Results (750 votes), past polls