<?xml version="1.0" encoding="windows-1252"?>
<node id="1015876" title="Re: Interpolating variables in JSON string" created="2013-01-29 08:52:54" updated="2013-01-29 08:52:54">
<type id="11">
note</type>
<author id="333489">
muba</author>
<data>
<field name="doctext">
&lt;p&gt;The line
&lt;c&gt;
    my $json = quotemeta( {"auth":{"RAX-KSKEY:apiKeyCredentials":{"username":$USERNAME, "apiKey":$API_KEY}}} );
&lt;/c&gt;
makes no sense. The character &lt;c&gt;:&lt;/c&gt; 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.&lt;/p&gt; 

&lt;p&gt;The Perl equivalent of a JSON map is called a hash. Traditionally we use &lt;c&gt;=&gt;&lt;/c&gt; to separate keys from their values, not &lt;c&gt;:&lt;/c&gt;.&lt;/p&gt;
&lt;c&gt;
    my $json = quotemeta( {"auth" =&gt; {"RAX-KSKEY:apiKeyCredentials" =&gt; {"username" =&gt; $USERNAME, "apiKey" =&gt; $API_KEY}}} );
&lt;/c&gt;

&lt;p&gt;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 &lt;c&gt;"HASH\(0x33c218\)"&lt;/c&gt;. You don't need quotemeta here &amp;mdash; 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 &lt;i&gt;do&lt;/i&gt; need is a real JSON module, like the good monks before me already suggested.&lt;/p&gt;
</field>
<field name="root_node">
1015856</field>
<field name="parent_node">
1015856</field>
</data>
</node>
